introduced PostId and PostStatus and changed naming from Storage to Persistence

This commit is contained in:
Dominik Liebler
2018-06-14 18:28:40 +02:00
parent 2ab82dbfbf
commit 6c726d66b7
18 changed files with 334 additions and 743 deletions

View File

@@ -5,10 +5,15 @@ namespace DesignPatterns\More\Repository\Domain;
class Post
{
/**
* @var int
* @var PostId
*/
private $id;
/**
* @var PostStatus
*/
private $status;
/**
* @var string
*/
@@ -19,10 +24,11 @@ class Post
*/
private $text;
public static function draft(int $id, string $title, string $text): Post
public static function draft(PostId $id, string $title, string $text): Post
{
return new self(
$id,
PostStatus::fromString(PostStatus::STATE_DRAFT),
$title,
$text
);
@@ -31,29 +37,37 @@ class Post
public static function fromState(array $state): Post
{
return new self(
$state['id'],
PostId::fromInt($state['id']),
PostStatus::fromInt($state['statusId']),
$state['title'],
$state['text']
);
}
/**
* @param int $id
* @param string $text
* @param PostId $id
* @param PostStatus $status
* @param string $title
* @param string $text
*/
private function __construct(int $id, string $title, string $text)
private function __construct(PostId $id, PostStatus $status, string $title, string $text)
{
$this->id = $id;
$this->status = $status;
$this->text = $text;
$this->title = $title;
}
public function getId(): int
public function getId(): PostId
{
return $this->id;
}
public function getStatus(): PostStatus
{
return $this->status;
}
public function getText(): string
{
return $this->text;