mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-13 09:56:21 +02:00
63 lines
985 B
PHP
63 lines
985 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\More\Repository;
|
|
|
|
class Post
|
|
{
|
|
/**
|
|
* @var int|null
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $title;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $text;
|
|
|
|
public static function fromState(array $state): Post
|
|
{
|
|
return new self(
|
|
$state['id'],
|
|
$state['title'],
|
|
$state['text']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param int|null $id
|
|
* @param string $text
|
|
* @param string $title
|
|
*/
|
|
public function __construct($id, string $title, string $text)
|
|
{
|
|
$this->id = $id;
|
|
$this->text = $text;
|
|
$this->title = $title;
|
|
}
|
|
|
|
public function setId(int $id)
|
|
{
|
|
$this->id = $id;
|
|
}
|
|
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getText(): string
|
|
{
|
|
return $this->text;
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
}
|