mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
committed by
GitHub
parent
abe81c15a9
commit
628d3dfc55
+11
-11
@@ -293,7 +293,7 @@ class Uuid implements UuidInterface
|
||||
*/
|
||||
public function serialize(): string
|
||||
{
|
||||
return $this->getFields()->getBytes();
|
||||
return $this->codec->encode($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,20 +446,20 @@ class Uuid implements UuidInterface
|
||||
*/
|
||||
public static function fromBytes(string $bytes): UuidInterface
|
||||
{
|
||||
if (! self::$factoryReplaced && strlen($bytes) === 16) {
|
||||
if (!self::$factoryReplaced && strlen($bytes) === 16) {
|
||||
$base16Uuid = bin2hex($bytes);
|
||||
|
||||
// Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID
|
||||
return self::fromString(
|
||||
substr($base16Uuid, 0, 8)
|
||||
. '-'
|
||||
. substr($base16Uuid, 8, 4)
|
||||
. '-'
|
||||
. substr($base16Uuid, 12, 4)
|
||||
. '-'
|
||||
. substr($base16Uuid, 16, 4)
|
||||
. '-'
|
||||
. substr($base16Uuid, 20, 12)
|
||||
. '-'
|
||||
. substr($base16Uuid, 8, 4)
|
||||
. '-'
|
||||
. substr($base16Uuid, 12, 4)
|
||||
. '-'
|
||||
. substr($base16Uuid, 16, 4)
|
||||
. '-'
|
||||
. substr($base16Uuid, 20, 12)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ class Uuid implements UuidInterface
|
||||
public static function fromString(string $uuid): UuidInterface
|
||||
{
|
||||
$uuid = strtolower($uuid);
|
||||
if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
|
||||
if (!self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
|
||||
assert($uuid !== '');
|
||||
|
||||
return new LazyUuidFromString($uuid);
|
||||
|
||||
Reference in New Issue
Block a user