src/Domain/Whater/Model/WhaterPointAttributeTypeChoice.php line 15

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