Files
DesignPatternsPHP/More/EAV/Entity.php
Dominik Liebler 461d612b91 PHP7 More
2016-09-22 15:51:45 +02:00

42 lines
707 B
PHP

<?php
namespace DesignPatterns\More\EAV;
class Entity
{
/**
* @var \SplObjectStorage
*/
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);
}
}