src/Domain/Zones/Model/District.php line 17

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Zones\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 District
  11. *
  12. * @package Whater\Domain\Zones\Model
  13. */
  14. class District implements ContainsRecordedEvents
  15. {
  16. use EventRecorderCapabilities;
  17. /**
  18. * @var string
  19. */
  20. private $uuid;
  21. /**
  22. * @var string
  23. */
  24. private $slug;
  25. /**
  26. * @var string
  27. */
  28. private $name;
  29. /**
  30. * @var Town
  31. */
  32. private $town;
  33. /**
  34. * @var Collection
  35. */
  36. private $whaterPoints;
  37. /**
  38. * @var \DateTime
  39. */
  40. private $createdAt;
  41. /**
  42. * @var \DateTime
  43. */
  44. private $updatedAt;
  45. /**
  46. * @param string $districtId
  47. * @param Town $town
  48. * @param string $name
  49. * @param string $slug
  50. */
  51. public function __construct(
  52. string $districtId = null,
  53. Town $town,
  54. string $name,
  55. string $slug = null
  56. ) {
  57. try {
  58. $this->uuid = Uuid::fromString($districtId ?: Uuid::uuid4())->toString();
  59. } catch (\InvalidArgumentException $e) {
  60. throw new InvalidUUIDException();
  61. }
  62. $this->town = $town;
  63. $this->slug = $slug;
  64. $this->name = $name;
  65. $this->whaterPoints = new ArrayCollection();
  66. $this->createdAt = new \DateTime();
  67. $this->updatedAt = new \DateTime();
  68. }
  69. public function updateDistrictData(
  70. string $name,
  71. string $slug = null
  72. ) {
  73. $this->name = $name;
  74. $this->slug = $slug;
  75. $this->updatedAt = new \DateTime();
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function id(): string
  81. {
  82. return $this->uuid;
  83. }
  84. /**
  85. * @return string
  86. */
  87. public function name(): string
  88. {
  89. return $this->name;
  90. }
  91. /**
  92. * @return string
  93. */
  94. public function slug(): ?string
  95. {
  96. return $this->slug;
  97. }
  98. /**
  99. * @return Town
  100. */
  101. public function town(): Town
  102. {
  103. return $this->town;
  104. }
  105. /**
  106. * @return Collection
  107. */
  108. public function whaterPoints(): Collection
  109. {
  110. return $this->whaterPoints;
  111. }
  112. /**
  113. * @return \DateTime
  114. */
  115. public function createdAt(): \DateTime
  116. {
  117. return $this->createdAt;
  118. }
  119. /**
  120. * @return \DateTime
  121. */
  122. public function updatedAt(): \DateTime
  123. {
  124. return $this->updatedAt;
  125. }
  126. /**
  127. * @return bool
  128. */
  129. public function equals(District $district)
  130. {
  131. return $this->id() === $district->id();
  132. }
  133. }