src/Entity/Tag/Tag.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Tag;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\Tag\TagRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Ramsey\Uuid\Doctrine\UuidGenerator;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Serializer\Annotation\SerializedName;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass=TagRepository::class)
  14.  *
  15.  * @ApiResource(
  16.  *     attributes={
  17.  *          "normalization_context"={"groups"={
  18.  *              "Tag:output",
  19.  *              "Tag:io",
  20.  *              "Blog:output",
  21.  *          }},
  22.  *          "denormalization_context"={"groups"={
  23.  *              "Tag:input",
  24.  *              "Tag:io",
  25.  *          }}
  26.  *      },
  27.  *     collectionOperations={},
  28.  *     itemOperations={},
  29.  * )
  30.  *
  31.  * @ORM\InheritanceType("SINGLE_TABLE")
  32.  * @ORM\DiscriminatorColumn(name="discr", type="string")
  33.  * @ORM\DiscriminatorMap({"blog" = "BlogTag"})
  34.  */
  35. abstract class Tag
  36. {
  37.     /**
  38.      * Hook timestampable behavior
  39.      * updates createdAt, updatedAt fields
  40.      */
  41.     use TimestampableEntity;
  42.     /**
  43.      * @ORM\Id
  44.      * @ORM\Column(type="uuid", unique=true)
  45.      * @ORM\GeneratedValue(strategy="CUSTOM")
  46.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  47.      * @SerializedName("id")
  48.      * @ApiProperty(identifier=true)
  49.      * @Assert\Uuid()
  50.      * @Groups({
  51.      *     "Tag:output",
  52.      *     "Blog:output",
  53.      * })
  54.      */
  55.     protected $id;
  56.     /**
  57.      * @ORM\Column(type="string", length=255)
  58.      * @Groups({
  59.      *     "Tag:output",
  60.      *     "Blog:output",
  61.      * })
  62.      */
  63.     private ?string $title;
  64.     public function getId(): ?string
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getTitle(): ?string
  69.     {
  70.         return $this->title;
  71.     }
  72.     public function setTitle(string $title): self
  73.     {
  74.         $this->title $title;
  75.         return $this;
  76.     }
  77.     public function __toString(): string
  78.     {
  79.         return $this->title;
  80.     }
  81.     /**
  82.      * @SerializedName("created_at")
  83.      * @Groups({
  84.      *     "Tag:output",
  85.      *     "Blog:output",
  86.      * })
  87.      * @return string
  88.      */
  89.     public function getSerializeCreatedAt(): string
  90.     {
  91.         return $this->getCreatedAt()->format('Y-m-d H:i:s');
  92.     }
  93. }