src/Domain/Blog/Model/ArticleTranslation.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 ArticleTranslation
  12. *
  13. * @package Whater\Domain\Blog\Model
  14. */
  15. class ArticleTranslation 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 string
  32. */
  33. private $content;
  34. /**
  35. * @var array
  36. */
  37. private $metaKeywords;
  38. /**
  39. * @var string
  40. */
  41. private $metaDescription;
  42. /**
  43. * @var string
  44. */
  45. private $locale;
  46. /**
  47. * @var Article
  48. */
  49. private $article;
  50. /**
  51. * @var null|\DateTime
  52. */
  53. private $createdAt;
  54. /**
  55. * @var null|\DateTime
  56. */
  57. private $updatedAt;
  58. public function __construct(
  59. string $articleTranslationId = null,
  60. Article $article,
  61. string $locale,
  62. string $title,
  63. string $slug,
  64. string $content,
  65. array $metaKeywords = [],
  66. string $metaDescription = null
  67. ) {
  68. try {
  69. $this->uuid = Uuid::fromString($articleTranslationId ?: Uuid::uuid4())->toString();
  70. } catch (\InvalidArgumentException $e) {
  71. throw new InvalidUUIDException();
  72. }
  73. $this->article = $article;
  74. $this->title = $title;
  75. $this->locale = $locale;
  76. $this->slug = $slug;
  77. $this->content = $content;
  78. $this->metaKeywords = $metaKeywords;
  79. $this->metaDescription = $metaDescription;
  80. $this->createdAt = new \DateTime();
  81. $this->updatedAt = $this->createdAt();
  82. }
  83. public function updateArticleTranslation(
  84. string $title = null,
  85. string $slug = null,
  86. string $content = null,
  87. array $metaKeywords = null,
  88. string $metaDescription = null
  89. ): ArticleTranslation {
  90. if (!is_null($title)) {
  91. $this->title = $title;
  92. }
  93. if (!is_null($slug)) {
  94. $this->slug = $slug;
  95. }
  96. if (!is_null($content)) {
  97. $this->content = $content;
  98. }
  99. if (!is_null($metaKeywords)) {
  100. $this->metaKeywords = $metaKeywords;
  101. }
  102. if (!is_null($metaDescription)) {
  103. $this->metaDescription = $metaDescription;
  104. }
  105. $this->updatedAt = new \DateTime();
  106. return $this;
  107. }
  108. /**
  109. * @return string
  110. */
  111. public function id(): string
  112. {
  113. return $this->uuid;
  114. }
  115. /**
  116. * @return string
  117. */
  118. public function title(): string
  119. {
  120. return $this->title;
  121. }
  122. /**
  123. * @return string
  124. */
  125. public function slug(): string
  126. {
  127. return $this->slug;
  128. }
  129. /**
  130. * @return string
  131. */
  132. public function content(): string
  133. {
  134. return $this->content;
  135. }
  136. /**
  137. * @return array
  138. */
  139. public function metaKeywords(): array
  140. {
  141. return $this->metaKeywords;
  142. }
  143. /**
  144. * @return string
  145. */
  146. public function metaDescription(): ?string
  147. {
  148. return $this->metaDescription;
  149. }
  150. /**
  151. * @return string
  152. */
  153. public function locale(): string
  154. {
  155. return $this->locale;
  156. }
  157. /**
  158. * @return \DateTime
  159. */
  160. public function createdAt(): \DateTime
  161. {
  162. return $this->createdAt;
  163. }
  164. /**
  165. * @return \DateTime
  166. */
  167. public function updatedAt(): \DateTime
  168. {
  169. return $this->updatedAt;
  170. }
  171. }