Files
DesignPatternsPHP/More/EAV/Entity.php
Mario Simão 56970cc221 style: Adopt PSR12
Dev dependency flyeralarm/php-code-validator has been removed.

Closes #444
2021-10-01 10:26:04 -03:00

39 lines
687 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);
}
}