/** * Uuid constructor * @param string|null $uuid */ public function __construct($uuid = null) { if ($uuid instanceof Uuid) { $uuid = $uuid->toString(); } elseif (null === $uuid) { $uuid = UuidV4::generate(); } elseif (!UuidV4::validate($uuid)) { throw new \InvalidArgumentException('Invalid UUID string given'); } $this->uuid = $uuid; }
/** * @param string|null $uuid * @throws InvalidArgumentException */ public function __construct($uuid = null) { if (null === $uuid) { $uuid = Uuid::generate(); } else { if (!Uuid::validate($uuid)) { throw new InvalidArgumentException('Given string is not valid v4 UUID'); } } $this->uuid = (string) $uuid; }