-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.php
More file actions
65 lines (57 loc) · 2.48 KB
/
Copy pathEntity.php
File metadata and controls
65 lines (57 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace TinyBlocks\BuildingBlocks\Entity;
use TinyBlocks\BuildingBlocks\Internal\Exceptions\MissingIdentityProperty;
/**
* Object whose identity persists through time and changes of state.
*
* <p>An entity is distinguished not by its attributes but by a thread of identity that remains stable
* across distinct representations and lifecycle transitions. Two entities are equal when their
* identities are equal, regardless of attribute differences.</p>
*
* <p>Concrete entities implement the protected <code>identityProperty()</code> method returning the property
* that holds their {@see Identity}. The default behavior uses reflection to resolve and compare it.</p>
*
* @see Eric Evans, <em>Domain-Driven Design: Tackling Complexity in the Heart of Software</em>
* (Addison-Wesley, 2003), Chapter 5 "Entities (a.k.a. Reference Objects)".
*/
interface Entity
{
/**
* Returns the Identity that uniquely identifies this entity.
*
* @return Identity The identity instance held by this entity.
* @throws MissingIdentityProperty When the property referenced by <code>identityProperty()</code> does not exist.
*/
public function identity(): Identity;
/**
* Returns the name of the property that holds this entity's Identity.
*
* @return string The property name, resolved from <code>identityProperty()</code>.
* @throws MissingIdentityProperty When the property referenced by <code>identityProperty()</code> does not exist.
*/
public function identityName(): string;
/**
* Returns the raw value of this entity's identity.
*
* <p>The shape of the returned value depends on the kind of identity held: a scalar for
* {@see SingleIdentity}, an associative array for {@see CompoundIdentity}.</p>
*
* @return mixed The raw identity value.
*/
public function identityValue(): mixed;
/**
* Checks whether this entity and the given one share the same identity.
*
* @param Entity $other The entity whose identity will be compared.
* @return bool True when both entities hold equal identities.
*/
public function sameIdentityOf(Entity $other): bool;
/**
* Checks whether the given Identity is equal to this entity's identity.
*
* @param Identity $other The identity to compare against.
* @return bool True when the given identity equals this entity's identity.
*/
public function identityEquals(Identity $other): bool;
}