1 | <?php |
||
24 | final class EntityId |
||
25 | { |
||
26 | /** |
||
27 | * The identifier. Usually a database id. |
||
28 | * |
||
29 | * @var mixed |
||
30 | */ |
||
31 | private $identifier; |
||
32 | |||
33 | /** |
||
34 | * The provider name. Usually the database table name. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $providerName; |
||
39 | |||
40 | /** |
||
41 | * Construct. |
||
42 | * |
||
43 | * @param string $providerName The provider name. |
||
44 | * @param mixed $identifier The identifier. |
||
45 | */ |
||
46 | private function __construct(string $providerName, $identifier) |
||
56 | |||
57 | /** |
||
58 | * Great the entity id from an string. |
||
59 | * |
||
60 | * @param string $entityId Entity id as string representation. For example provider::2. |
||
61 | * |
||
62 | * @return static |
||
63 | */ |
||
64 | public static function fromString(string $entityId): self |
||
73 | |||
74 | /** |
||
75 | * Create the entity id by provider name and identifier. |
||
76 | * |
||
77 | * @param string $providerName The provider name. |
||
78 | * @param mixed $identifier The identifier. |
||
79 | * |
||
80 | * @return static |
||
81 | */ |
||
82 | public static function fromProviderNameAndId(string $providerName, $identifier): self |
||
86 | |||
87 | /** |
||
88 | * Get the identifier. |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function getIdentifier() |
||
96 | |||
97 | /** |
||
98 | * Get the provider name. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function getProviderName(): string |
||
106 | |||
107 | /** |
||
108 | * Consider if it is equal with another entity id. |
||
109 | * |
||
110 | * @param EntityId $entityId The entity id to compare with. |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function equals(EntityId $entityId): bool |
||
118 | |||
119 | /** |
||
120 | * Cast entity id to string. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | public function __toString(): string |
||
128 | } |
||
129 |