src/Entity/Developers/ApiToken.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Developers;
  3. use App\Entity\Sync\SyncableInterface;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  9. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  10. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  11. use Nellapp\Bundle\SDKBundle\Developers\Entity\ApiClient\ApiClientInterface;
  12. use Nellapp\Bundle\SDKBundle\Developers\Entity\ApiToken\ApiTokenInterface;
  13. use Nellapp\Bundle\SDKBundle\Developers\Entity\ApiToken\ApiTokenMethodTrait;
  14. use Nellapp\Bundle\SDKBundle\Developers\Entity\ApiTokenChannelAccess\ApiTokenChannelAccessInterface;
  15. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  16. use Symfony\Component\Serializer\Annotation as Serial;
  17. #[ORM\Entity]
  18. #[ORM\Table(name: 'developers_api_token')]
  19. class ApiToken implements ApiTokenInterface, TimestampInterface, SyncableInterface
  20. {
  21. use ApiTokenMethodTrait;
  22. use TimestampTrait;
  23. #[ORM\Id]
  24. #[ORM\GeneratedValue]
  25. #[ORM\Column]
  26. #[Serial\Groups(['Sync'])]
  27. private ?int $id = null;
  28. #[ORM\ManyToOne(targetEntity: ApiClientInterface::class, inversedBy: 'tokens')]
  29. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  30. #[IdGroups(['Sync'])]
  31. private ?ApiClientInterface $client = null;
  32. #[ORM\Column(length: 255, nullable: false)]
  33. #[Serial\Groups(['Sync'])]
  34. private ?string $name = null;
  35. #[ORM\Column(length: 32, unique: true)]
  36. #[Serial\Groups(['Sync'])]
  37. private ?string $prefix = null;
  38. #[ORM\Column(length: 255)]
  39. #[Serial\Groups(['Sync'])]
  40. private ?string $hash = null;
  41. #[ORM\Column(type: Types::SIMPLE_ARRAY)]
  42. #[Serial\Groups(['Sync'])]
  43. private array $scopes = [];
  44. #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
  45. #[Serial\Groups(['Sync'])]
  46. private ?\DateTimeImmutable $expiresAt = null;
  47. #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
  48. #[Serial\Groups(['Sync'])]
  49. private ?\DateTimeImmutable $revokedAt = null;
  50. #[ORM\OneToMany(
  51. mappedBy: 'token',
  52. targetEntity: ApiTokenChannelAccessInterface::class,
  53. cascade: ['persist', 'remove'],
  54. orphanRemoval: true
  55. )]
  56. private Collection $channelAccesses;
  57. public function __construct() {
  58. $this->channelAccesses = new ArrayCollection();
  59. }
  60. public static function getSyncKey(): string
  61. {
  62. return EntityKeys::DEVELOPERS_API_TOKEN;
  63. }
  64. public function getSyncDisplayLabel(): string
  65. {
  66. return $this->getPrefix() ?? 'token prefix';
  67. }
  68. }