forked from DomainDrivers/dd-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourceId.php
45 lines (35 loc) · 863 Bytes
/
ResourceId.php
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
<?php
declare(strict_types=1);
namespace DomainDrivers\SmartSchedule\Availability;
use Symfony\Component\Uid\Uuid;
final readonly class ResourceId implements \Stringable
{
public function __construct(public ?Uuid $id)
{
}
public static function newOne(): self
{
return new self(Uuid::v7());
}
public static function none(): self
{
return new self(null);
}
public static function fromString(string $id): self
{
return new self(Uuid::fromString($id));
}
public function getId(): Uuid
{
return $this->id ?? throw new \RuntimeException('ResourceId not set');
}
public function toString(): ?string
{
return $this->id?->toRfc4122();
}
#[\Override]
public function __toString(): string
{
return $this->toString() ?? '';
}
}