File size: 1,215 Bytes
cf14c12 | 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 | <?php
declare(strict_types=1);
namespace Shared\Domain\ValueObjects;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Ramsey\Uuid\Doctrine\UuidV7Generator;
use Ramsey\Uuid\Exception\UnsupportedOperationException;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Embeddable]
class Id implements JsonSerializable
{
#[ORM\Id]
#[ORM\Column(name: "id", type: "uuid_binary", unique: true)]
#[ORM\GeneratedValue(strategy: "NONE")]
#[ORM\CustomIdGenerator(class: UuidV7Generator::class)]
private UuidInterface $value;
/**
* @param null|string $value
* @return void
* @throws UnsupportedOperationException
*/
public function __construct(?string $value = null)
{
$this->value = is_null($value)
? Uuid::uuid7()
: Uuid::fromString($value);
}
/** @return UuidInterface */
public function getValue(): UuidInterface
{
return $this->value;
}
/** @inheritDoc */
public function jsonSerialize(): string
{
return $this->value->toString();
}
public function equals(Id $id): bool
{
return $this->value->toString() === $id->getValue()->toString();
}
}
|