UserTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace Test\PhpDevCommunity\PaperORM\Entity;
  3. use Cassandra\Time;
  4. use PhpDevCommunity\PaperORM\Collection\ObjectStorage;
  5. use PhpDevCommunity\PaperORM\Entity\EntityInterface;
  6. use PhpDevCommunity\PaperORM\Mapping\Column\BoolColumn;
  7. use PhpDevCommunity\PaperORM\Mapping\Column\StringColumn;
  8. use PhpDevCommunity\PaperORM\Mapping\Column\DateTimeColumn;
  9. use PhpDevCommunity\PaperORM\Mapping\Column\JoinColumn;
  10. use PhpDevCommunity\PaperORM\Mapping\Column\PrimaryKeyColumn;
  11. use PhpDevCommunity\PaperORM\Mapping\Column\TimestampColumn;
  12. use PhpDevCommunity\PaperORM\Mapping\Column\TokenColumn;
  13. use PhpDevCommunity\PaperORM\Mapping\Entity;
  14. use PhpDevCommunity\PaperORM\Mapping\OneToMany;
  15. use Test\PhpDevCommunity\PaperORM\Repository\PostTestRepository;
  16. #[Entity(table : 'user', repository : null)]
  17. class UserTest implements EntityInterface
  18. {
  19. #[PrimaryKeyColumn]
  20. private ?int $id = null;
  21. #[StringColumn]
  22. private ?string $firstname = null;
  23. #[StringColumn]
  24. private ?string $lastname = null;
  25. #[StringColumn]
  26. private ?string $email = null;
  27. #[StringColumn]
  28. private ?string $password = null;
  29. #[TokenColumn(length: 32)]
  30. private ?string $token = null;
  31. #[BoolColumn(name: 'is_active')]
  32. private bool $active = false;
  33. #[TimestampColumn( onCreated: true)]
  34. private ?\DateTimeInterface $createdAt = null;
  35. #[OneToMany(targetEntity: PostTest::class, mappedBy: 'user')]
  36. private ObjectStorage $posts;
  37. #[JoinColumn(name: 'last_post_id', targetEntity: PostTest::class, nullable: true, unique: true, onDelete: JoinColumn::SET_NULL)]
  38. private ?PostTest $lastPost = null;
  39. public function __construct()
  40. {
  41. $this->posts = new ObjectStorage();
  42. }
  43. static public function getTableName(): string
  44. {
  45. return 'user';
  46. }
  47. static public function getRepositoryName(): ?string
  48. {
  49. return null;
  50. }
  51. static public function columnsMapping(): array
  52. {
  53. if (PHP_VERSION_ID > 80000) {
  54. return [];
  55. }
  56. return [
  57. (new PrimaryKeyColumn())->bindProperty('id'),
  58. (new StringColumn())->bindProperty('firstname'),
  59. (new StringColumn())->bindProperty('lastname'),
  60. (new StringColumn())->bindProperty('email'),
  61. (new StringColumn())->bindProperty('password'),
  62. (new TokenColumn(null, 32))->bindProperty('token'),
  63. (new BoolColumn( 'is_active'))->bindProperty('active'),
  64. (new TimestampColumn( null, true))->bindProperty('createdAt'),
  65. (new OneToMany( PostTest::class, 'user'))->bindProperty('posts'),
  66. (new JoinColumn( 'last_post_id', PostTest::class, 'id', true, true, JoinColumn::SET_NULL))->bindProperty('lastPost'),
  67. ];
  68. }
  69. public function getPrimaryKeyValue() : ?int
  70. {
  71. return $this->getId();
  72. }
  73. public function getId(): ?int
  74. {
  75. return $this->id;
  76. }
  77. public function setId(?int $id): UserTest
  78. {
  79. $this->id = $id;
  80. return $this;
  81. }
  82. public function getFirstname(): ?string
  83. {
  84. return $this->firstname;
  85. }
  86. public function setFirstname(?string $firstname): UserTest
  87. {
  88. $this->firstname = $firstname;
  89. return $this;
  90. }
  91. public function getLastname(): ?string
  92. {
  93. return $this->lastname;
  94. }
  95. public function setLastname(?string $lastname): UserTest
  96. {
  97. $this->lastname = $lastname;
  98. return $this;
  99. }
  100. public function getEmail(): ?string
  101. {
  102. return $this->email;
  103. }
  104. public function setEmail(?string $email): UserTest
  105. {
  106. $this->email = $email;
  107. return $this;
  108. }
  109. public function getPassword(): ?string
  110. {
  111. return $this->password;
  112. }
  113. public function setPassword(?string $password): UserTest
  114. {
  115. $this->password = $password;
  116. return $this;
  117. }
  118. public function getToken(): ?string
  119. {
  120. return $this->token;
  121. }
  122. public function setToken(?string $token): UserTest
  123. {
  124. $this->token = $token;
  125. return $this;
  126. }
  127. public function isActive(): bool
  128. {
  129. return $this->active;
  130. }
  131. public function setActive(bool $active): UserTest
  132. {
  133. $this->active = $active;
  134. return $this;
  135. }
  136. public function getCreatedAt(): ?\DateTimeInterface
  137. {
  138. return $this->createdAt;
  139. }
  140. public function setCreatedAt(?\DateTimeInterface $createdAt): UserTest
  141. {
  142. $this->createdAt = $createdAt;
  143. return $this;
  144. }
  145. public function getPosts(): ObjectStorage
  146. {
  147. return $this->posts;
  148. }
  149. public function addPost(PostTest $post): UserTest
  150. {
  151. $this->posts->add($post);
  152. return $this;
  153. }
  154. public function getLastPost(): ?PostTest
  155. {
  156. return $this->lastPost;
  157. }
  158. public function setLastPost(?PostTest $lastPost): UserTest
  159. {
  160. $this->lastPost = $lastPost;
  161. return $this;
  162. }
  163. }