8000 docs · msgphp/msgphp@c9d5b32 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9d5b32

Browse files
committed
docs
1 parent d9f4886 commit c9d5b32

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/ddd/entities.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# Entities
22

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+
37
Domain entities are "[vanilla] PHP objects". To simplify its model definition common _fields_ and _features_ are
48
provided in the form of [traits].
59

10+
## Identities
11+
12+
Use identities to simplify the entity its identity definition. Built-in identities are:
13+
14+
- `MsgPhp\Domain\Model\IntIdentity`
15+
616
## Entity Fields
717

818
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
2434

2535
use MsgPhp\Domain\Model\CreatedAtField;
2636
use MsgPhp\Domain\Model\CanBeEnabled;
37+
use MsgPhp\Domain\Model\IntIdentity;
2738

2839
// SETUP
2940

3041
class MyEntity
3142
{
43+
use IntIdentity;
3244
use CreatedAtField;
3345
use CanBeEnabled;
3446

@@ -41,12 +53,20 @@ class MyEntity
4153
// USAGE
4254

4355
$entity = new MyEntity();
56+
$entity->getId()->isNil(); // true
57+
4458
$createdAt = $entity->getCreatedAt();
4559

4660
if (!$entity->isEnabled()) {
4761
$entity->enable();
4862
}
4963
```
5064

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+
5170
[vanilla]: https://en.wikipedia.org/wiki/Plain_vanilla
5271
[traits]: https://secure.php.net/traits
72+
[covariance]: https://www.php.net/manual/en/language.oop5.variance.php#language.oop5.variance.covariance

0 commit comments

Comments
 (0)
0