Files
DesignPatternsPHP/More/Repository/Domain/Post.php
2018-06-14 17:45:45 +02:00

67 lines
1.1 KiB
PHP

<?php
namespace DesignPatterns\More\Repository\Domain;
class Post
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $title;
/**
* @var string
*/
private $text;
public static function draft(int $id, string $title, string $text): Post
{
return new self(
$id,
$title,
$text
);
}
public static function fromState(array $state): Post
{
return new self(
$state['id'],
$state['title'],
$state['text']
);
}
/**
* @param int $id
* @param string $text
* @param string $title
*/
private function __construct(int $id, string $title, string $text)
{
$this->id = $id;
$this->text = $text;
$this->title = $title;
}
public function getId(): int
{
return $this->id;
}
public function getText(): string
{
return $this->text;
}
public function getTitle(): string
{
return $this->title;
}
}