src/Domain/Blog/Model/ArticleCategoryTranslation.php line 18

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