-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPersonId.php
More file actions
48 lines (39 loc) · 945 Bytes
/
PersonId.php
File metadata and controls
48 lines (39 loc) · 945 Bytes
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
<?php
namespace MatchBot\Domain;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* UUID of a person as given by our Identity service
*/
#[Embeddable]
readonly class PersonId
{
#[Column(type: 'uuid')]
public readonly UuidInterface $id;
private function __construct(string $personId)
{
$this->id = Uuid::fromString($personId);
}
public static function of(string $personId): self
{
return new self($personId);
}
public static function ofUUID(UuidInterface $personId): self
{
return new self($personId->toString());
}
public function equals(self $that): bool
{
return $this->id->equals($that->id);
}
public function toUUID(): UuidInterface
{
return $this->id;
}
public static function nil(): self
{
return self::of(Uuid::NIL);
}
}