<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\User\Referent;
use App\Entity\User\User;
use App\Repository\TokenRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=TokenRepository::class)
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={
* "Token:output",
* "Token:io"
* }},
* "denormalization_context"={"groups"={
* "Token:input",
* "Token:io"
* }}
* },
* collectionOperations={
* "get"={
* "access_control"="is_granted('ROLE_USER')",
* },
* "post"={
* "validation_groups"={"Default", "Create"}
* },
* },
* itemOperations={
* "get"={
* "path"="/public/tokens/{id}",
* },
* }
* )
*/
class Token
{
public const NAME_FORGOTTEN_PASSWORD = 'forgotten_password';
public const NAME_INITIALIZATION_PASSWORD = 'initialization_password';
public const MAX_REQUEST_FORGOTTEN_PASSWORD = 3;
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @ApiProperty(identifier=true)
* @Assert\Uuid()
* @Groups({"Token:output"})
*/
private string $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="tokens")
* @SerializedName("user")
* @Groups({"Token:output"})
*/
private $user;
/**
* @ORM\Column(type="string", length=30)
* @SerializedName("name")
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Referent::class, inversedBy="tokens")
*/
private $referent;
/**
* @return string
*/
public function getId(): ?string
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @Groups({"Token:io"})
* @SerializedName("created_at")
*/
public function getCreatedAtTimestampable(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function getReferent(): ?Referent
{
return $this->referent;
}
public function setReferent(?Referent $referent): self
{
$this->referent = $referent;
return $this;
}
}