src/Domain/Product/Model/ProductAttribute.php line 17

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Product\Model;
  3. use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
  4. use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Ramsey\Uuid\Uuid;
  8. use Whater\Domain\Common\Exception\InvalidUUIDException;
  9. /**
  10. * Class ProductAttribute
  11. *
  12. * @package Whater\Domain\productAttribute\Model
  13. */
  14. class ProductAttribute implements ContainsRecordedEvents
  15. {
  16. use EventRecorderCapabilities;
  17. /**
  18. * @var string
  19. */
  20. private $uuid;
  21. /**
  22. * @var string
  23. */
  24. private $productAttributeName;
  25. /**
  26. * @var string
  27. */
  28. private $productAttributeSlug;
  29. /**
  30. * @var \DateTime
  31. */
  32. private $createdAt;
  33. /**
  34. * @var null|\DateTime
  35. */
  36. private $updatedAt;
  37. /**
  38. * @var array
  39. */
  40. private $productAttributeTerms;
  41. /**
  42. * @var Collection
  43. */
  44. private $products;
  45. /**
  46. * @param string $productAttributeId
  47. */
  48. public function __construct(
  49. string $productAttributeId = null,
  50. string $productAttributeName
  51. ) {
  52. try {
  53. $this->uuid = Uuid::fromString($productAttributeId ?: Uuid::uuid4())->toString();
  54. } catch (\InvalidArgumentException $e) {
  55. throw new InvalidUUIDException();
  56. }
  57. $this->productAttributeName = $productAttributeName;
  58. $this->productAttributeSlug = $productAttributeName;
  59. $this->products = new ArrayCollection();
  60. $this->createdAt = new \DateTime();
  61. $this->updatedAt = new \DateTime();
  62. }
  63. public function editproductAttribute(
  64. string $productAttributeName,
  65. string $productAttributeSlug = null,
  66. array $productAttributeTerms = null
  67. ) {
  68. $this->productAttributeName = $productAttributeName;
  69. $this->productAttributeSlug = $productAttributeSlug;
  70. $this->productAttributeTerms = $productAttributeTerms;
  71. $this->updatedAt = new \DateTime();
  72. }
  73. /**
  74. * @return string
  75. */
  76. public function id(): string
  77. {
  78. return $this->uuid;
  79. }
  80. /**
  81. * @return string
  82. */
  83. public function productAttributeName(): string
  84. {
  85. return $this->productAttributeName;
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function productAttributeSlug(): string
  91. {
  92. return $this->productAttributeSlug;
  93. }
  94. /**
  95. * @return Collection
  96. */
  97. public function products(): Collection
  98. {
  99. return $this->products;
  100. }
  101. /**
  102. * @return \DateTime
  103. */
  104. public function createdAt(): \DateTime
  105. {
  106. return $this->createdAt;
  107. }
  108. /**
  109. * @return \DateTime|null
  110. */
  111. public function updatedAt()
  112. {
  113. return $this->updatedAt;
  114. }
  115. public function productAttributeTerms(): ?array
  116. {
  117. return $this->productAttributeTerms;
  118. }
  119. /**
  120. * @return bool
  121. */
  122. public function equals(ProductAttribute $productAttribute)
  123. {
  124. return $this->id() === $productAttribute->id();
  125. }
  126. }