From 905da079bee9683207b512825a6f9752d17fce12 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 21 Aug 2015 12:34:29 +0300 Subject: [PATCH] Add missing sections to README file --- More/EAV/README.rst | 139 +++++++++++++++++++++++-------------------- More/EAV/example.php | 14 ++--- 2 files changed, 82 insertions(+), 71 deletions(-) diff --git a/More/EAV/README.rst b/More/EAV/README.rst index 0a03ad7..b8a8fbe 100644 --- a/More/EAV/README.rst +++ b/More/EAV/README.rst @@ -1,87 +1,97 @@ `Entity-Attribute-Value (EAV)`__ ================================ +The Entity–attribute–value (EAV) pattern in order to implement EAV model with PHP. + Purpose ------- -... +The Entity–attribute–value (EAV) model is a data model to describe entities +where the number of attributes (properties, parameters) that can be used +to describe them is potentially vast, but the number that will actually apply +to a given entity is relatively modest. Examples -------- -``` -use DesignPatterns\More\EAV\Entity; -use DesignPatterns\More\EAV\Attribute; -use DesignPatterns\More\EAV\Value; +Check full work example in `example.php`_ file. -// color attribute -$color = (new Attribute())->setName('Color'); -// color values -$colorSilver = (new Value($color))->setName('Silver'); -$colorGold = (new Value($color))->setName('Gold'); -$colorSpaceGrey = (new Value($color))->setName('Space Grey'); +.. code-block:: php -// 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'); + use DesignPatterns\More\EAV\Entity; + use DesignPatterns\More\EAV\Attribute; + use DesignPatterns\More\EAV\Value; -// 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'); + // Create color attribute + $color = (new Attribute())->setName('Color'); + // Create color values + $colorSilver = (new Value($color))->setName('Silver'); + $colorGold = (new Value($color))->setName('Gold'); + $colorSpaceGrey = (new Value($color))->setName('Space Grey'); -// entities -$mac = (new Entity()) - ->setName('MacBook') - // colors - ->addValue($colorSilver) - ->addValue($colorGold) - ->addValue($colorSpaceGrey) - // memories - ->addValue($memory8Gb) - // storages - ->addValue($storage256Gb) - ->addValue($storage512Gb) -; + // Create memory attribute + $memory = (new Attribute())->setName('Memory'); + // Create memory values + $memory4Gb = (new Value($memory))->setName('4GB'); + $memory8Gb = (new Value($memory))->setName('8GB'); + $memory16Gb = (new Value($memory))->setName('16GB'); -$macAir = (new Entity()) - ->setName('MacBook Air') - // colors - ->addValue($colorSilver) - // memories - ->addValue($memory4Gb) - ->addValue($memory8Gb) - // storages - ->addValue($storage128Gb) - ->addValue($storage256Gb) - ->addValue($storage512Gb) -; + // Create storage attribute + $storage = (new Attribute())->setName('Storage'); + // Create 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'); + + // Create entities with specific values + $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) + ; -$macPro = (new Entity()) - ->setName('MacBook Pro') - // colors - ->addValue($colorSilver) - // memories - ->addValue($memory8Gb) - ->addValue($memory16Gb) - // storages - ->addValue($storage128Gb) - ->addValue($storage256Gb) - ->addValue($storage512Gb) - ->addValue($storage1Tb) -; -``` UML Diagram ----------- -... +.. image:: uml/uml.png + :alt: EAV UML Diagram + :align: center Code ---- @@ -110,5 +120,6 @@ Tests/ValueTest.php :linenos: +.. _`example.php`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV/example.php .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV .. __: https://en.wikipedia.org/wiki/Entity–attribute–value_model diff --git a/More/EAV/example.php b/More/EAV/example.php index c69342e..c5bb5c4 100644 --- a/More/EAV/example.php +++ b/More/EAV/example.php @@ -6,29 +6,29 @@ use DesignPatterns\More\EAV\Entity; use DesignPatterns\More\EAV\Attribute; use DesignPatterns\More\EAV\Value; -// color attribute +// Create color attribute $color = (new Attribute())->setName('Color'); -// color values +// Create color values $colorSilver = (new Value($color))->setName('Silver'); $colorGold = (new Value($color))->setName('Gold'); $colorSpaceGrey = (new Value($color))->setName('Space Grey'); -// memory attribute +// Create memory attribute $memory = (new Attribute())->setName('Memory'); -// memory values +// Create memory values $memory4Gb = (new Value($memory))->setName('4GB'); $memory8Gb = (new Value($memory))->setName('8GB'); $memory16Gb = (new Value($memory))->setName('16GB'); -// storage attribute +// Create storage attribute $storage = (new Attribute())->setName('Storage'); -// storage values +// Create 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 +// Create entities with specific values $mac = (new Entity()) ->setName('MacBook') // colors