2015-07-20 18:32:30 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DesignPatterns\More\EAV;
|
|
|
|
|
|
|
|
/**
|
2015-12-21 07:28:20 -05:00
|
|
|
* Class Value.
|
2015-07-20 18:32:30 +03:00
|
|
|
*/
|
2015-07-21 10:57:01 +03:00
|
|
|
class Value implements ValueInterface
|
2015-07-20 18:32:30 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Attribute
|
|
|
|
*/
|
|
|
|
private $attribute;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
2015-07-21 10:57:01 +03:00
|
|
|
/**
|
|
|
|
* @param Attribute $attribute
|
|
|
|
*/
|
2015-07-20 18:32:30 +03:00
|
|
|
public function __construct(Attribute $attribute)
|
|
|
|
{
|
|
|
|
$attribute->addValue($this);
|
|
|
|
$this->attribute = $attribute;
|
|
|
|
}
|
|
|
|
|
2015-08-19 15:52:10 +03:00
|
|
|
/**
|
|
|
|
* @param Attribute $attribute
|
2015-12-21 07:28:20 -05:00
|
|
|
*
|
2015-11-16 13:52:07 +08:00
|
|
|
* @return $this
|
2015-08-19 15:52:10 +03:00
|
|
|
*/
|
|
|
|
public function setAttribute(Attribute $attribute)
|
|
|
|
{
|
|
|
|
$this->attribute->removeValue($this); // Remove value from current attribute
|
|
|
|
$attribute->addValue($this); // Add value to new attribute
|
|
|
|
$this->attribute = $attribute;
|
2015-11-16 13:52:07 +08:00
|
|
|
|
|
|
|
return $this;
|
2015-08-19 15:52:10 +03:00
|
|
|
}
|
|
|
|
|
2015-07-20 18:32:30 +03:00
|
|
|
/**
|
|
|
|
* @return Attribute
|
|
|
|
*/
|
|
|
|
public function getAttribute()
|
|
|
|
{
|
|
|
|
return $this->attribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
2015-12-21 07:28:20 -05:00
|
|
|
*
|
2015-07-20 18:32:30 +03:00
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setName($name)
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|