Skip to content

Commit

Permalink
Update UUID.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Smeagolworms4 committed Feb 28, 2020
1 parent baac044 commit 15fb9e1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/UUID.php
Expand Up @@ -8,14 +8,13 @@ class UUID implements UUIDInterface

public function __construct(string $uuid = null)
{
if ($uuid && !preg_match('/^[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\\-[a-f0-9]{4}\-[a-f0-9]{10}$/', $uuid)) {
throw new \LogicException('UUID not valid');
}
$s4 = function ()
{
$s4 = function () {
return substr(dechex((mt_rand(1000000000, 2000000000) / 1000000000) * hexdec('10000')) , 1);
};
$this->uuid = $uuid ? $uuid : ($s4() . $s4() . '-' . $s4() . '-' . $s4() . '-' . $s4() . '-' . substr(dechex(microtime(true) * 1000) , 1));
if (!preg_match('/^[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\\-[a-f0-9]{4}\-[a-f0-9]{10}$/', $this->uuid)) {
throw new \LogicException('UUID not valid');
}
}

public function __toString(): string
Expand Down

0 comments on commit 15fb9e1

Please sign in to comment.