| 1 | <?php |
||
| 21 | class UUID extends StringId |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @param string $value |
||
| 25 | * |
||
| 26 | * @return bool |
||
| 27 | */ |
||
| 28 | public static function isValidUUID($value) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $value |
||
| 37 | * |
||
| 38 | * @throws \InvalidArgumentException |
||
| 39 | */ |
||
| 40 | public function __construct($value = null) |
||
| 41 | { |
||
| 42 | if ($value !== null && !self::isValidUUID($value)) { |
||
| 43 | throw new \InvalidArgumentException(sprintf('Argument "%s" is an invalid UUID.', $value)); |
||
| 44 | } |
||
| 45 | |||
| 46 | $this->value = $value === null ? self::nextUUIDValue() : $value; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return static |
||
| 51 | */ |
||
| 52 | public static function next() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public static function nextUUIDValue() |
||
| 64 | } |
||
| 65 |