mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-23 17:22:41 +01:00
37 lines
686 B
PHP
37 lines
686 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\More\EAV;
|
|
|
|
use SplObjectStorage;
|
|
|
|
class Entity implements \Stringable
|
|
{
|
|
/**
|
|
* @var SplObjectStorage<Value,Value>
|
|
*/
|
|
private $values;
|
|
|
|
/**
|
|
* @param Value[] $values
|
|
*/
|
|
public function __construct(private string $name, $values)
|
|
{
|
|
$this->values = new SplObjectStorage();
|
|
|
|
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);
|
|
}
|
|
}
|