mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
PHP8
This commit is contained in:
@@ -4,15 +4,13 @@ namespace DesignPatterns\More\EAV;
|
||||
|
||||
use SplObjectStorage;
|
||||
|
||||
class Attribute
|
||||
class Attribute implements \Stringable
|
||||
{
|
||||
private SplObjectStorage $values;
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
public function __construct(private string $name)
|
||||
{
|
||||
$this->values = new SplObjectStorage();
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function addValue(Value $value)
|
||||
|
@@ -4,7 +4,7 @@ namespace DesignPatterns\More\EAV;
|
||||
|
||||
use SplObjectStorage;
|
||||
|
||||
class Entity
|
||||
class Entity implements \Stringable
|
||||
{
|
||||
/**
|
||||
* @var SplObjectStorage<Value,Value>
|
||||
@@ -12,19 +12,11 @@ class Entity
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $name;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param Value[] $values
|
||||
*/
|
||||
public function __construct(string $name, $values)
|
||||
public function __construct(private string $name, $values)
|
||||
{
|
||||
/** @var SplObjectStorage<Value,Value> values */
|
||||
$this->values = new SplObjectStorage();
|
||||
$this->name = $name;
|
||||
|
||||
foreach ($values as $value) {
|
||||
$this->values->attach($value);
|
||||
|
@@ -2,16 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\More\EAV;
|
||||
|
||||
class Value
|
||||
class Value implements \Stringable
|
||||
{
|
||||
private Attribute $attribute;
|
||||
private string $name;
|
||||
|
||||
public function __construct(Attribute $attribute, string $name)
|
||||
public function __construct(private Attribute $attribute, private string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->attribute = $attribute;
|
||||
|
||||
$attribute->addValue($this);
|
||||
}
|
||||
|
||||
|
@@ -4,11 +4,6 @@ namespace DesignPatterns\More\Repository\Domain;
|
||||
|
||||
class Post
|
||||
{
|
||||
private PostId $id;
|
||||
private PostStatus $status;
|
||||
private string $title;
|
||||
private string $text;
|
||||
|
||||
public static function draft(PostId $id, string $title, string $text): Post
|
||||
{
|
||||
return new self(
|
||||
@@ -29,12 +24,12 @@ class Post
|
||||
);
|
||||
}
|
||||
|
||||
private function __construct(PostId $id, PostStatus $status, string $title, string $text)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->status = $status;
|
||||
$this->text = $text;
|
||||
$this->title = $title;
|
||||
private function __construct(
|
||||
private PostId $id,
|
||||
private PostStatus $status,
|
||||
private string $title,
|
||||
private string $text
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): PostId
|
||||
|
@@ -13,8 +13,6 @@ use InvalidArgumentException;
|
||||
*/
|
||||
class PostId
|
||||
{
|
||||
private int $id;
|
||||
|
||||
public static function fromInt(int $id): PostId
|
||||
{
|
||||
self::ensureIsValid($id);
|
||||
@@ -22,9 +20,8 @@ class PostId
|
||||
return new self($id);
|
||||
}
|
||||
|
||||
private function __construct(int $id)
|
||||
private function __construct(private int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function toInt(): int
|
||||
|
@@ -21,9 +21,6 @@ class PostStatus
|
||||
self::STATE_PUBLISHED_ID => self::STATE_PUBLISHED,
|
||||
];
|
||||
|
||||
private int $id;
|
||||
private string $name;
|
||||
|
||||
public static function fromInt(int $statusId)
|
||||
{
|
||||
self::ensureIsValidId($statusId);
|
||||
@@ -43,10 +40,8 @@ class PostStatus
|
||||
return new self($state, $status);
|
||||
}
|
||||
|
||||
private function __construct(int $id, string $name)
|
||||
private function __construct(private int $id, private string $name)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function toInt(): int
|
||||
|
@@ -17,11 +17,8 @@ use DesignPatterns\More\Repository\Domain\PostId;
|
||||
*/
|
||||
class PostRepository
|
||||
{
|
||||
private Persistence $persistence;
|
||||
|
||||
public function __construct(Persistence $persistence)
|
||||
public function __construct(private Persistence $persistence)
|
||||
{
|
||||
$this->persistence = $persistence;
|
||||
}
|
||||
|
||||
public function generateId(): PostId
|
||||
|
Reference in New Issue
Block a user