TagTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Test\PhpDevCommunity\PaperORM\Entity;
  3. use PhpDevCommunity\PaperORM\Entity\EntityInterface;
  4. use PhpDevCommunity\PaperORM\Mapping\Column\StringColumn;
  5. use PhpDevCommunity\PaperORM\Mapping\Column\DateTimeColumn;
  6. use PhpDevCommunity\PaperORM\Mapping\Column\JoinColumn;
  7. use PhpDevCommunity\PaperORM\Mapping\Column\PrimaryKeyColumn;
  8. use PhpDevCommunity\PaperORM\Mapping\Entity;
  9. use Test\PhpDevCommunity\PaperORM\Repository\PostTestRepository;
  10. use Test\PhpDevCommunity\PaperORM\Repository\TagTestRepository;
  11. #[Entity(table : 'tag', repository : TagTestRepository::class)]
  12. class TagTest implements EntityInterface
  13. {
  14. #[PrimaryKeyColumn]
  15. private ?int $id = null;
  16. #[StringColumn]
  17. private ?string $name = null;
  18. #[JoinColumn(name : 'post_id', referencedColumnName : 'id', targetEntity : PostTest::class)]
  19. private ?PostTest $post = null;
  20. static public function getTableName(): string
  21. {
  22. return 'tag';
  23. }
  24. static public function getRepositoryName(): string
  25. {
  26. return TagTestRepository::class;
  27. }
  28. static public function columnsMapping(): array
  29. {
  30. if (PHP_VERSION_ID > 80000) {
  31. return [];
  32. }
  33. return [
  34. (new PrimaryKeyColumn())->bindProperty('id'),
  35. (new StringColumn())->bindProperty('name'),
  36. (new JoinColumn( 'post_id', 'id', PostTest::class))->bindProperty('post'),
  37. ];
  38. }
  39. public function getPrimaryKeyValue() : ?int
  40. {
  41. return $this->getId();
  42. }
  43. public function getId(): ?int
  44. {
  45. return $this->id;
  46. }
  47. public function getName(): ?string
  48. {
  49. return $this->name;
  50. }
  51. public function setName(?string $name): TagTest
  52. {
  53. $this->name = $name;
  54. return $this;
  55. }
  56. public function getPost(): ?PostTest
  57. {
  58. return $this->post;
  59. }
  60. public function setPost(?PostTest $post): TagTest
  61. {
  62. $this->post = $post;
  63. return $this;
  64. }
  65. }