File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Entities
2
2
3
+ > An object that is not defined by its attributes, but rather by a thread of continuity and its identity.
4
+ >
5
+ > — https://en.wikipedia.org/wiki/Domain-driven_design#Building_blocks
6
+
3
7
Domain entities are "[ vanilla] PHP objects". To simplify its model definition common _ fields_ and _ features_ are
4
8
provided in the form of [ traits] .
5
9
10
+ ## Identities
11
+
12
+ Use identities to simplify the entity its identity definition. Built-in identities are:
13
+
14
+ - ` MsgPhp\Domain\Model\IntIdentity `
15
+
6
16
## Entity Fields
7
17
8
18
Use entity fields to provide _ read operations_ for common entity fields. Built-in fields are:
@@ -24,11 +34,13 @@ Use entity features to provide _write operations_ for common entity fields. Buil
24
34
25
35
use MsgPhp\Domain\Model\CreatedAtField;
26
36
use MsgPhp\Domain\Model\CanBeEnabled;
37
+ use MsgPhp\Domain\Model\IntIdentity;
27
38
28
39
// SETUP
29
40
30
41
class MyEntity
31
42
{
43
+ use IntIdentity;
32
44
use CreatedAtField;
33
45
use CanBeEnabled;
34
46
@@ -41,12 +53,20 @@ class MyEntity
41
53
// USAGE
42
54
43
55
$entity = new MyEntity();
56
+ $entity->getId()->isNil(); // true
57
+
44
58
$createdAt = $entity->getCreatedAt();
45
59
46
60
if (!$entity->isEnabled()) {
47
61
$entity->enable();
48
62
}
49
63
```
50
64
65
+ !!! note
66
+ By default ` getId() ` returns a [ ` GenericDomainId ` ] ( identifiers.md#msgphpdomaingenericdomainid ) . Since the method is
67
+ derived from a trait [ covariance] is possible by default, thus it can be overridden to return any ` DomainId ` type
68
+ instead.
69
+
51
70
[ vanilla ] : https://en.wikipedia.org/wiki/Plain_vanilla
52
71
[ traits ] : https://secure.php.net/traits
72
+ [ covariance ] : https://www.php.net/manual/en/language.oop5.variance.php#language.oop5.variance.covariance
You can’t perform that action at this time.
0 commit comments