mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-21 14:02:40 +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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user