mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-09 09:34:46 +02:00
57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\More\Repository\Domain;
|
|
|
|
class Post
|
|
{
|
|
public static function draft(PostId $id, string $title, string $text): Post
|
|
{
|
|
return new self(
|
|
$id,
|
|
PostStatus::fromString(PostStatus::STATE_DRAFT),
|
|
$title,
|
|
$text
|
|
);
|
|
}
|
|
|
|
public static function fromState(array $state): Post
|
|
{
|
|
return new self(
|
|
PostId::fromInt($state['id']),
|
|
PostStatus::fromInt($state['statusId']),
|
|
$state['title'],
|
|
$state['text']
|
|
);
|
|
}
|
|
|
|
private function __construct(
|
|
private PostId $id,
|
|
private PostStatus $status,
|
|
private string $title,
|
|
private string $text
|
|
) {
|
|
}
|
|
|
|
public function getId(): PostId
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getStatus(): PostStatus
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function getText(): string
|
|
{
|
|
return $this->text;
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
}
|