mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Add support for PHP 8.1
This commit is contained in:
@@ -23,10 +23,12 @@ use Ramsey\Uuid\Lazy\LazyUuidFromString;
|
||||
use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
use Ramsey\Uuid\Type\Integer as IntegerObject;
|
||||
use ValueError;
|
||||
|
||||
use function assert;
|
||||
use function bin2hex;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strcmp;
|
||||
use function strlen;
|
||||
@@ -289,6 +291,14 @@ class Uuid implements UuidInterface
|
||||
return $this->getFields()->getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{bytes: string}
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return ['bytes' => $this->serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-constructs the object from its serialized form
|
||||
*
|
||||
@@ -313,6 +323,18 @@ class Uuid implements UuidInterface
|
||||
$this->timeConverter = $uuid->timeConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{bytes: string} $data
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
if (!isset($data['bytes'])) {
|
||||
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
|
||||
}
|
||||
|
||||
$this->unserialize($data['bytes']);
|
||||
}
|
||||
|
||||
public function compareTo(UuidInterface $other): int
|
||||
{
|
||||
$compare = strcmp($this->toString(), $other->toString());
|
||||
|
||||
Reference in New Issue
Block a user