<?php
namespace Whater\Domain\Blog\Model;
use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Ramsey\Uuid\Uuid;
use Assert\Assertion;
use Whater\Domain\Common\Exception\InvalidUUIDException;
/**
* Class ArticleTranslation
*
* @package Whater\Domain\Blog\Model
*/
class ArticleTranslation implements ContainsRecordedEvents
{
use EventRecorderCapabilities;
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $title;
/**
* @var string
*/
private $slug;
/**
* @var string
*/
private $content;
/**
* @var array
*/
private $metaKeywords;
/**
* @var string
*/
private $metaDescription;
/**
* @var string
*/
private $locale;
/**
* @var Article
*/
private $article;
/**
* @var null|\DateTime
*/
private $createdAt;
/**
* @var null|\DateTime
*/
private $updatedAt;
public function __construct(
string $articleTranslationId = null,
Article $article,
string $locale,
string $title,
string $slug,
string $content,
array $metaKeywords = [],
string $metaDescription = null
) {
try {
$this->uuid = Uuid::fromString($articleTranslationId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->article = $article;
$this->title = $title;
$this->locale = $locale;
$this->slug = $slug;
$this->content = $content;
$this->metaKeywords = $metaKeywords;
$this->metaDescription = $metaDescription;
$this->createdAt = new \DateTime();
$this->updatedAt = $this->createdAt();
}
public function updateArticleTranslation(
string $title = null,
string $slug = null,
string $content = null,
array $metaKeywords = null,
string $metaDescription = null
): ArticleTranslation {
if (!is_null($title)) {
$this->title = $title;
}
if (!is_null($slug)) {
$this->slug = $slug;
}
if (!is_null($content)) {
$this->content = $content;
}
if (!is_null($metaKeywords)) {
$this->metaKeywords = $metaKeywords;
}
if (!is_null($metaDescription)) {
$this->metaDescription = $metaDescription;
}
$this->updatedAt = new \DateTime();
return $this;
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return string
*/
public function title(): string
{
return $this->title;
}
/**
* @return string
*/
public function slug(): string
{
return $this->slug;
}
/**
* @return string
*/
public function content(): string
{
return $this->content;
}
/**
* @return array
*/
public function metaKeywords(): array
{
return $this->metaKeywords;
}
/**
* @return string
*/
public function metaDescription(): ?string
{
return $this->metaDescription;
}
/**
* @return string
*/
public function locale(): string
{
return $this->locale;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
/**
* @return \DateTime
*/
public function updatedAt(): \DateTime
{
return $this->updatedAt;
}
}