2
0

UserTest.php 4.5 KB

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