forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.php
43 lines (34 loc) · 766 Bytes
/
Entity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php declare(strict_types=1);
namespace DesignPatterns\More\EAV;
use SplObjectStorage;
class Entity
{
/**
* @var SplObjectStorage<Value,Value>
*/
private $values;
/**
* @var string
*/
private $name;
/**
* @param string $name
* @param Value[] $values
*/
public function __construct(string $name, $values)
{
$this->values = new SplObjectStorage();
$this->name = $name;
foreach ($values as $value) {
$this->values->attach($value);
}
}
public function __toString(): string
{
$text = [$this->name];
foreach ($this->values as $value) {
$text[] = (string) $value;
}
return join(', ', $text);
}
}