diff --git a/More/EAV/Attribute.php b/More/EAV/Attribute.php new file mode 100644 index 0000000..43a5d4c --- /dev/null +++ b/More/EAV/Attribute.php @@ -0,0 +1,71 @@ +values; + } + + /** + * @param Value|ValueInterface $value + * @return $this + */ + public function addValue(ValueInterface $value) + { + // @TODO I think the $value should be checked for uniqueness first to avoid duplication in array. + $this->values[] = $value; + + return $this; + } + + /** + * @param Value|ValueInterface $value + * @return $this + */ + public function removeValue(ValueInterface $value) + { + if ($key = array_search($value, $this->values, true)) { + unset($this->values[$key]); + } + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/More/EAV/Entity.php b/More/EAV/Entity.php new file mode 100644 index 0000000..7234b7d --- /dev/null +++ b/More/EAV/Entity.php @@ -0,0 +1,71 @@ +values; + } + + /** + * @param Value|ValueInterface $value + * @return $this + */ + public function addValue(ValueInterface $value) + { + // @TODO I think the $value should be checked for uniqueness first to avoid duplication in array. + $this->values[] = $value; + + return $this; + } + + /** + * @param Value|ValueInterface $value + * @return $this + */ + public function removeValue(ValueInterface $value) + { + if ($key = array_search($value, $this->values, true)) { + unset($this->values[$key]); + } + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/More/EAV/Value.php b/More/EAV/Value.php new file mode 100644 index 0000000..362ac5c --- /dev/null +++ b/More/EAV/Value.php @@ -0,0 +1,52 @@ +addValue($this); + $this->attribute = $attribute; + } + + /** + * @return Attribute + */ + public function getAttribute() + { + return $this->attribute; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/More/EAV/ValueInterface.php b/More/EAV/ValueInterface.php new file mode 100644 index 0000000..e0c299a --- /dev/null +++ b/More/EAV/ValueInterface.php @@ -0,0 +1,24 @@ +setName('Color'); +// color values +$colorSilver = (new Value($color))->setName('Silver'); +$colorGold = (new Value($color))->setName('Gold'); +$colorSpaceGrey = (new Value($color))->setName('Space Grey'); + +// memory attribute +$memory = (new Attribute())->setName('Memory'); +// memory values +$memory4Gb = (new Value($memory))->setName('4GB'); +$memory8Gb = (new Value($memory))->setName('8GB'); +$memory16Gb = (new Value($memory))->setName('16GB'); + +// storage attribute +$storage = (new Attribute())->setName('Storage'); +// storage values +$storage128Gb = (new Value($storage))->setName('128GB'); +$storage256Gb = (new Value($storage))->setName('256GB'); +$storage512Gb = (new Value($storage))->setName('512GB'); +$storage1Tb = (new Value($storage))->setName('1TB'); + +// entities +$mac = (new Entity()) + ->setName('MacBook') + // colors + ->addValue($colorSilver) + ->addValue($colorGold) + ->addValue($colorSpaceGrey) + // memories + ->addValue($memory8Gb) + // storages + ->addValue($storage256Gb) + ->addValue($storage512Gb) +; + +$macAir = (new Entity()) + ->setName('MacBook Air') + // colors + ->addValue($colorSilver) + // memories + ->addValue($memory4Gb) + ->addValue($memory8Gb) + // storages + ->addValue($storage128Gb) + ->addValue($storage256Gb) + ->addValue($storage512Gb) +; + +$macPro = (new Entity()) + ->setName('MacBook Pro') + // colors + ->addValue($colorSilver) + // memories + ->addValue($memory8Gb) + ->addValue($memory16Gb) + // storages + ->addValue($storage128Gb) + ->addValue($storage256Gb) + ->addValue($storage512Gb) + ->addValue($storage1Tb) +;