src/Entity/Token.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\User\Referent;
  6. use App\Entity\User\User;
  7. use App\Repository\TokenRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Ramsey\Uuid\Doctrine\UuidGenerator;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\SerializedName;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass=TokenRepository::class)
  16.  * @ApiResource(
  17.  *     attributes={
  18.  *          "normalization_context"={"groups"={
  19.  *              "Token:output",
  20.  *              "Token:io"
  21.  *          }},
  22.  *          "denormalization_context"={"groups"={
  23.  *              "Token:input",
  24.  *              "Token:io"
  25.  *          }}
  26.  *      },
  27.  *     collectionOperations={
  28.  *          "get"={
  29.  *              "access_control"="is_granted('ROLE_USER')",
  30.  *          },
  31.  *          "post"={
  32.  *              "validation_groups"={"Default", "Create"}
  33.  *          },
  34.  *     },
  35.  *     itemOperations={
  36.  *          "get"={
  37.  *              "path"="/public/tokens/{id}",
  38.  *          },
  39.  *     }
  40.  * )
  41.  */
  42. class Token
  43. {
  44.     public const NAME_FORGOTTEN_PASSWORD 'forgotten_password';
  45.     public const NAME_INITIALIZATION_PASSWORD 'initialization_password';
  46.     public const MAX_REQUEST_FORGOTTEN_PASSWORD 3;
  47.     /**
  48.      * Hook timestampable behavior
  49.      * updates createdAt, updatedAt fields
  50.      */
  51.     use TimestampableEntity;
  52.     /**
  53.      * @ORM\Id
  54.      * @ORM\Column(type="uuid", unique=true)
  55.      * @ORM\GeneratedValue(strategy="CUSTOM")
  56.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  57.      * @SerializedName("id")
  58.      * @ApiProperty(identifier=true)
  59.      * @Assert\Uuid()
  60.      * @Groups({"Token:output"})
  61.      */
  62.     private string $id;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="tokens")
  65.      * @SerializedName("user")
  66.      * @Groups({"Token:output"})
  67.      */
  68.     private $user;
  69.     /**
  70.      * @ORM\Column(type="string", length=30)
  71.      * @SerializedName("name")
  72.      */
  73.     private $name;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity=Referent::class, inversedBy="tokens")
  76.      */
  77.     private $referent;
  78.     /**
  79.      * @return string
  80.      */
  81.     public function getId(): ?string
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getUser(): ?User
  86.     {
  87.         return $this->user;
  88.     }
  89.     public function setUser(?User $user): self
  90.     {
  91.         $this->user $user;
  92.         return $this;
  93.     }
  94.     public function getName(): ?string
  95.     {
  96.         return $this->name;
  97.     }
  98.     public function setName(string $name): self
  99.     {
  100.         $this->name $name;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @Groups({"Token:io"})
  105.      * @SerializedName("created_at")
  106.      */
  107.     public function getCreatedAtTimestampable(): ?\DateTimeInterface
  108.     {
  109.         return $this->createdAt;
  110.     }
  111.     public function getReferent(): ?Referent
  112.     {
  113.         return $this->referent;
  114.     }
  115.     public function setReferent(?Referent $referent): self
  116.     {
  117.         $this->referent $referent;
  118.         return $this;
  119.     }
  120. }