mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-06 06:25:48 +02:00
Add missing sections to README file
This commit is contained in:
parent
4d3b024c71
commit
905da079be
@ -1,43 +1,51 @@
|
|||||||
`Entity-Attribute-Value (EAV)`__
|
`Entity-Attribute-Value (EAV)`__
|
||||||
================================
|
================================
|
||||||
|
|
||||||
|
The Entity–attribute–value (EAV) pattern in order to implement EAV model with PHP.
|
||||||
|
|
||||||
Purpose
|
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
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
||||||
```
|
Check full work example in `example.php`_ file.
|
||||||
use DesignPatterns\More\EAV\Entity;
|
|
||||||
use DesignPatterns\More\EAV\Attribute;
|
|
||||||
use DesignPatterns\More\EAV\Value;
|
|
||||||
|
|
||||||
// color attribute
|
.. code-block:: php
|
||||||
$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');
|
|
||||||
|
|
||||||
// memory attribute
|
use DesignPatterns\More\EAV\Entity;
|
||||||
$memory = (new Attribute())->setName('Memory');
|
use DesignPatterns\More\EAV\Attribute;
|
||||||
// memory values
|
use DesignPatterns\More\EAV\Value;
|
||||||
$memory4Gb = (new Value($memory))->setName('4GB');
|
|
||||||
$memory8Gb = (new Value($memory))->setName('8GB');
|
|
||||||
$memory16Gb = (new Value($memory))->setName('16GB');
|
|
||||||
|
|
||||||
// storage attribute
|
// Create color attribute
|
||||||
$storage = (new Attribute())->setName('Storage');
|
$color = (new Attribute())->setName('Color');
|
||||||
// storage values
|
// Create color values
|
||||||
$storage128Gb = (new Value($storage))->setName('128GB');
|
$colorSilver = (new Value($color))->setName('Silver');
|
||||||
$storage256Gb = (new Value($storage))->setName('256GB');
|
$colorGold = (new Value($color))->setName('Gold');
|
||||||
$storage512Gb = (new Value($storage))->setName('512GB');
|
$colorSpaceGrey = (new Value($color))->setName('Space Grey');
|
||||||
$storage1Tb = (new Value($storage))->setName('1TB');
|
|
||||||
|
|
||||||
// entities
|
// Create memory attribute
|
||||||
$mac = (new Entity())
|
$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');
|
||||||
|
|
||||||
|
// 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')
|
->setName('MacBook')
|
||||||
// colors
|
// colors
|
||||||
->addValue($colorSilver)
|
->addValue($colorSilver)
|
||||||
@ -48,9 +56,9 @@ $mac = (new Entity())
|
|||||||
// storages
|
// storages
|
||||||
->addValue($storage256Gb)
|
->addValue($storage256Gb)
|
||||||
->addValue($storage512Gb)
|
->addValue($storage512Gb)
|
||||||
;
|
;
|
||||||
|
|
||||||
$macAir = (new Entity())
|
$macAir = (new Entity())
|
||||||
->setName('MacBook Air')
|
->setName('MacBook Air')
|
||||||
// colors
|
// colors
|
||||||
->addValue($colorSilver)
|
->addValue($colorSilver)
|
||||||
@ -61,9 +69,9 @@ $macAir = (new Entity())
|
|||||||
->addValue($storage128Gb)
|
->addValue($storage128Gb)
|
||||||
->addValue($storage256Gb)
|
->addValue($storage256Gb)
|
||||||
->addValue($storage512Gb)
|
->addValue($storage512Gb)
|
||||||
;
|
;
|
||||||
|
|
||||||
$macPro = (new Entity())
|
$macPro = (new Entity())
|
||||||
->setName('MacBook Pro')
|
->setName('MacBook Pro')
|
||||||
// colors
|
// colors
|
||||||
->addValue($colorSilver)
|
->addValue($colorSilver)
|
||||||
@ -75,13 +83,15 @@ $macPro = (new Entity())
|
|||||||
->addValue($storage256Gb)
|
->addValue($storage256Gb)
|
||||||
->addValue($storage512Gb)
|
->addValue($storage512Gb)
|
||||||
->addValue($storage1Tb)
|
->addValue($storage1Tb)
|
||||||
;
|
;
|
||||||
```
|
|
||||||
|
|
||||||
UML Diagram
|
UML Diagram
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
...
|
.. image:: uml/uml.png
|
||||||
|
:alt: EAV UML Diagram
|
||||||
|
:align: center
|
||||||
|
|
||||||
Code
|
Code
|
||||||
----
|
----
|
||||||
@ -110,5 +120,6 @@ Tests/ValueTest.php
|
|||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
|
|
||||||
|
.. _`example.php`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV/example.php
|
||||||
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV
|
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV
|
||||||
.. __: https://en.wikipedia.org/wiki/Entity–attribute–value_model
|
.. __: https://en.wikipedia.org/wiki/Entity–attribute–value_model
|
||||||
|
@ -6,29 +6,29 @@ use DesignPatterns\More\EAV\Entity;
|
|||||||
use DesignPatterns\More\EAV\Attribute;
|
use DesignPatterns\More\EAV\Attribute;
|
||||||
use DesignPatterns\More\EAV\Value;
|
use DesignPatterns\More\EAV\Value;
|
||||||
|
|
||||||
// color attribute
|
// Create color attribute
|
||||||
$color = (new Attribute())->setName('Color');
|
$color = (new Attribute())->setName('Color');
|
||||||
// color values
|
// Create color values
|
||||||
$colorSilver = (new Value($color))->setName('Silver');
|
$colorSilver = (new Value($color))->setName('Silver');
|
||||||
$colorGold = (new Value($color))->setName('Gold');
|
$colorGold = (new Value($color))->setName('Gold');
|
||||||
$colorSpaceGrey = (new Value($color))->setName('Space Grey');
|
$colorSpaceGrey = (new Value($color))->setName('Space Grey');
|
||||||
|
|
||||||
// memory attribute
|
// Create memory attribute
|
||||||
$memory = (new Attribute())->setName('Memory');
|
$memory = (new Attribute())->setName('Memory');
|
||||||
// memory values
|
// Create memory values
|
||||||
$memory4Gb = (new Value($memory))->setName('4GB');
|
$memory4Gb = (new Value($memory))->setName('4GB');
|
||||||
$memory8Gb = (new Value($memory))->setName('8GB');
|
$memory8Gb = (new Value($memory))->setName('8GB');
|
||||||
$memory16Gb = (new Value($memory))->setName('16GB');
|
$memory16Gb = (new Value($memory))->setName('16GB');
|
||||||
|
|
||||||
// storage attribute
|
// Create storage attribute
|
||||||
$storage = (new Attribute())->setName('Storage');
|
$storage = (new Attribute())->setName('Storage');
|
||||||
// storage values
|
// Create storage values
|
||||||
$storage128Gb = (new Value($storage))->setName('128GB');
|
$storage128Gb = (new Value($storage))->setName('128GB');
|
||||||
$storage256Gb = (new Value($storage))->setName('256GB');
|
$storage256Gb = (new Value($storage))->setName('256GB');
|
||||||
$storage512Gb = (new Value($storage))->setName('512GB');
|
$storage512Gb = (new Value($storage))->setName('512GB');
|
||||||
$storage1Tb = (new Value($storage))->setName('1TB');
|
$storage1Tb = (new Value($storage))->setName('1TB');
|
||||||
|
|
||||||
// entities
|
// Create entities with specific values
|
||||||
$mac = (new Entity())
|
$mac = (new Entity())
|
||||||
->setName('MacBook')
|
->setName('MacBook')
|
||||||
// colors
|
// colors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user