UserTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace Test\PhpDevCommunity\PaperORM\Entity;
  3. use PhpDevCommunity\PaperORM\Collection\ObjectStorage;
  4. use PhpDevCommunity\PaperORM\Entity\EntityInterface;
  5. use PhpDevCommunity\PaperORM\Mapping\Column\BoolColumn;
  6. use PhpDevCommunity\PaperORM\Mapping\Column\StringColumn;
  7. use PhpDevCommunity\PaperORM\Mapping\Column\DateTimeColumn;
  8. use PhpDevCommunity\PaperORM\Mapping\Column\JoinColumn;
  9. use PhpDevCommunity\PaperORM\Mapping\Column\PrimaryKeyColumn;
  10. use PhpDevCommunity\PaperORM\Mapping\OneToMany;
  11. class UserTest implements EntityInterface
  12. {
  13. private ?int $id = null;
  14. private ?string $firstname = null;
  15. private ?string $lastname = null;
  16. private ?string $email = null;
  17. private ?string $password = null;
  18. private bool $active = false;
  19. private ?\DateTime $createdAt = null;
  20. private ObjectStorage $posts;
  21. private ?PostTest $lastPost = null;
  22. public function __construct()
  23. {
  24. $this->posts = new ObjectStorage();
  25. $this->createdAt = new \DateTime();
  26. }
  27. static public function getTableName(): string
  28. {
  29. return 'user';
  30. }
  31. static public function getRepositoryName(): ?string
  32. {
  33. return null;
  34. }
  35. static public function columnsMapping(): array
  36. {
  37. return [
  38. new PrimaryKeyColumn('id'),
  39. new StringColumn('firstname'),
  40. new StringColumn('lastname'),
  41. new StringColumn('email'),
  42. new StringColumn('password'),
  43. new BoolColumn('active', 'is_active'),
  44. new DateTimeColumn('createdAt', 'created_at'),
  45. new OneToMany('posts', PostTest::class, 'user'),
  46. new JoinColumn('lastPost', 'last_post_id', 'id', PostTest::class),
  47. ];
  48. }
  49. public function getPrimaryKeyValue() : ?int
  50. {
  51. return $this->getId();
  52. }
  53. public function getId(): ?int
  54. {
  55. return $this->id;
  56. }
  57. public function setId(?int $id): UserTest
  58. {
  59. $this->id = $id;
  60. return $this;
  61. }
  62. public function getFirstname(): ?string
  63. {
  64. return $this->firstname;
  65. }
  66. public function setFirstname(?string $firstname): UserTest
  67. {
  68. $this->firstname = $firstname;
  69. return $this;
  70. }
  71. public function getLastname(): ?string
  72. {
  73. return $this->lastname;
  74. }
  75. public function setLastname(?string $lastname): UserTest
  76. {
  77. $this->lastname = $lastname;
  78. return $this;
  79. }
  80. public function getEmail(): ?string
  81. {
  82. return $this->email;
  83. }
  84. public function setEmail(?string $email): UserTest
  85. {
  86. $this->email = $email;
  87. return $this;
  88. }
  89. public function getPassword(): ?string
  90. {
  91. return $this->password;
  92. }
  93. public function setPassword(?string $password): UserTest
  94. {
  95. $this->password = $password;
  96. return $this;
  97. }
  98. public function isActive(): bool
  99. {
  100. return $this->active;
  101. }
  102. public function setActive(bool $active): UserTest
  103. {
  104. $this->active = $active;
  105. return $this;
  106. }
  107. public function getCreatedAt(): ?\DateTime
  108. {
  109. return $this->createdAt;
  110. }
  111. public function setCreatedAt(?\DateTime $createdAt): UserTest
  112. {
  113. $this->createdAt = $createdAt;
  114. return $this;
  115. }
  116. public function getPosts(): ObjectStorage
  117. {
  118. return $this->posts;
  119. }
  120. public function addPost(PostTest $post): UserTest
  121. {
  122. $this->posts->add($post);
  123. return $this;
  124. }
  125. public function getLastPost(): ?PostTest
  126. {
  127. return $this->lastPost;
  128. }
  129. public function setLastPost(?PostTest $lastPost): UserTest
  130. {
  131. $this->lastPost = $lastPost;
  132. return $this;
  133. }
  134. }