Skip to content

Commit 905da07

Browse files
committed
Add missing sections to README file
1 parent 4d3b024 commit 905da07

File tree

2 files changed

+88
-77
lines changed

2 files changed

+88
-77
lines changed

More/EAV/README.rst

Lines changed: 81 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,97 @@
11
`Entity-Attribute-Value (EAV)`__
22
================================
33

4+
The Entity–attribute–value (EAV) pattern in order to implement EAV model with PHP.
5+
46
Purpose
57
-------
68

7-
...
9+
The Entity–attribute–value (EAV) model is a data model to describe entities
10+
where the number of attributes (properties, parameters) that can be used
11+
to describe them is potentially vast, but the number that will actually apply
12+
to a given entity is relatively modest.
813

914
Examples
1015
--------
1116

12-
```
13-
use DesignPatterns\More\EAV\Entity;
14-
use DesignPatterns\More\EAV\Attribute;
15-
use DesignPatterns\More\EAV\Value;
16-
17-
// color attribute
18-
$color = (new Attribute())->setName('Color');
19-
// color values
20-
$colorSilver = (new Value($color))->setName('Silver');
21-
$colorGold = (new Value($color))->setName('Gold');
22-
$colorSpaceGrey = (new Value($color))->setName('Space Grey');
23-
24-
// memory attribute
25-
$memory = (new Attribute())->setName('Memory');
26-
// memory values
27-
$memory4Gb = (new Value($memory))->setName('4GB');
28-
$memory8Gb = (new Value($memory))->setName('8GB');
29-
$memory16Gb = (new Value($memory))->setName('16GB');
30-
31-
// storage attribute
32-
$storage = (new Attribute())->setName('Storage');
33-
// storage values
34-
$storage128Gb = (new Value($storage))->setName('128GB');
35-
$storage256Gb = (new Value($storage))->setName('256GB');
36-
$storage512Gb = (new Value($storage))->setName('512GB');
37-
$storage1Tb = (new Value($storage))->setName('1TB');
38-
39-
// entities
40-
$mac = (new Entity())
41-
->setName('MacBook')
42-
// colors
43-
->addValue($colorSilver)
44-
->addValue($colorGold)
45-
->addValue($colorSpaceGrey)
46-
// memories
47-
->addValue($memory8Gb)
48-
// storages
49-
->addValue($storage256Gb)
50-
->addValue($storage512Gb)
51-
;
52-
53-
$macAir = (new Entity())
54-
->setName('MacBook Air')
55-
// colors
56-
->addValue($colorSilver)
57-
// memories
58-
->addValue($memory4Gb)
59-
->addValue($memory8Gb)
60-
// storages
61-
->addValue($storage128Gb)
62-
->addValue($storage256Gb)
63-
->addValue($storage512Gb)
64-
;
65-
66-
$macPro = (new Entity())
67-
->setName('MacBook Pro')
68-
// colors
69-
->addValue($colorSilver)
70-
// memories
71-
->addValue($memory8Gb)
72-
->addValue($memory16Gb)
73-
// storages
74-
->addValue($storage128Gb)
75-
->addValue($storage256Gb)
76-
->addValue($storage512Gb)
77-
->addValue($storage1Tb)
78-
;
79-
```
17+
Check full work example in `example.php`_ file.
18+
19+
.. code-block:: php
20+
21+
use DesignPatterns\More\EAV\Entity;
22+
use DesignPatterns\More\EAV\Attribute;
23+
use DesignPatterns\More\EAV\Value;
24+
25+
// Create color attribute
26+
$color = (new Attribute())->setName('Color');
27+
// Create color values
28+
$colorSilver = (new Value($color))->setName('Silver');
29+
$colorGold = (new Value($color))->setName('Gold');
30+
$colorSpaceGrey = (new Value($color))->setName('Space Grey');
31+
32+
// Create memory attribute
33+
$memory = (new Attribute())->setName('Memory');
34+
// Create memory values
35+
$memory4Gb = (new Value($memory))->setName('4GB');
36+
$memory8Gb = (new Value($memory))->setName('8GB');
37+
$memory16Gb = (new Value($memory))->setName('16GB');
38+
39+
// Create storage attribute
40+
$storage = (new Attribute())->setName('Storage');
41+
// Create storage values
42+
$storage128Gb = (new Value($storage))->setName('128GB');
43+
$storage256Gb = (new Value($storage))->setName('256GB');
44+
$storage512Gb = (new Value($storage))->setName('512GB');
45+
$storage1Tb = (new Value($storage))->setName('1TB');
46+
47+
// Create entities with specific values
48+
$mac = (new Entity())
49+
->setName('MacBook')
50+
// colors
51+
->addValue($colorSilver)
52+
->addValue($colorGold)
53+
->addValue($colorSpaceGrey)
54+
// memories
55+
->addValue($memory8Gb)
56+
// storages
57+
->addValue($storage256Gb)
58+
->addValue($storage512Gb)
59+
;
60+
61+
$macAir = (new Entity())
62+
->setName('MacBook Air')
63+
// colors
64+
->addValue($colorSilver)
65+
// memories
66+
->addValue($memory4Gb)
67+
->addValue($memory8Gb)
68+
// storages
69+
->addValue($storage128Gb)
70+
->addValue($storage256Gb)
71+
->addValue($storage512Gb)
72+
;
73+
74+
$macPro = (new Entity())
75+
->setName('MacBook Pro')
76+
// colors
77+
->addValue($colorSilver)
78+
// memories
79+
->addValue($memory8Gb)
80+
->addValue($memory16Gb)
81+
// storages
82+
->addValue($storage128Gb)
83+
->addValue($storage256Gb)
84+
->addValue($storage512Gb)
85+
->addValue($storage1Tb)
86+
;
87+
8088
8189
UML Diagram
8290
-----------
8391

84-
...
92+
.. image:: uml/uml.png
93+
:alt: EAV UML Diagram
94+
:align: center
8595

8696
Code
8797
----
@@ -110,5 +120,6 @@ Tests/ValueTest.php
110120
:linenos:
111121

112122

123+
.. _`example.php`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV/example.php
113124
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/EAV
114125
.. __: https://en.wikipedia.org/wiki/Entity–attribute–value_model

More/EAV/example.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@
66
use DesignPatterns\More\EAV\Attribute;
77
use DesignPatterns\More\EAV\Value;
88

9-
// color attribute
9+
// Create color attribute
1010
$color = (new Attribute())->setName('Color');
11-
// color values
11+
// Create color values
1212
$colorSilver = (new Value($color))->setName('Silver');
1313
$colorGold = (new Value($color))->setName('Gold');
1414
$colorSpaceGrey = (new Value($color))->setName('Space Grey');
1515

16-
// memory attribute
16+
// Create memory attribute
1717
$memory = (new Attribute())->setName('Memory');
18-
// memory values
18+
// Create memory values
1919
$memory4Gb = (new Value($memory))->setName('4GB');
2020
$memory8Gb = (new Value($memory))->setName('8GB');
2121
$memory16Gb = (new Value($memory))->setName('16GB');
2222

23-
// storage attribute
23+
// Create storage attribute
2424
$storage = (new Attribute())->setName('Storage');
25-
// storage values
25+
// Create storage values
2626
$storage128Gb = (new Value($storage))->setName('128GB');
2727
$storage256Gb = (new Value($storage))->setName('256GB');
2828
$storage512Gb = (new Value($storage))->setName('512GB');
2929
$storage1Tb = (new Value($storage))->setName('1TB');
3030

31-
// entities
31+
// Create entities with specific values
3232
$mac = (new Entity())
3333
->setName('MacBook')
3434
// colors

0 commit comments

Comments
 (0)