PHP7 More

This commit is contained in:
Dominik Liebler
2016-09-22 15:51:45 +02:00
parent 2b1de13391
commit 461d612b91
11 changed files with 84 additions and 617 deletions

View File

@@ -2,12 +2,10 @@
namespace DesignPatterns\More\EAV;
use SplObjectStorage;
class Entity implements ValueAccessInterface
class Entity
{
/**
* @var SplObjectStorage
* @var \SplObjectStorage
*/
private $values;
@@ -16,64 +14,28 @@ class Entity implements ValueAccessInterface
*/
private $name;
public function __construct()
{
$this->values = new SplObjectStorage();
}
/**
* @return SplObjectStorage
*/
public function getValues()
{
return $this->values;
}
/**
* @param ValueInterface $value
*
* @return $this
*/
public function addValue(ValueInterface $value)
{
if (!$this->values->contains($value)) {
$this->values->attach($value);
}
return $this;
}
/**
* @param ValueInterface $value
*
* @return $this
*/
public function removeValue(ValueInterface $value)
{
if ($this->values->contains($value)) {
$this->values->detach($value);
}
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return $this
* @param Value[] $values
*/
public function setName($name)
public function __construct(string $name, $values)
{
$this->values = new \SplObjectStorage();
$this->name = $name;
return $this;
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);
}
}