Add support for PHP 8.1

This commit is contained in:
Graham Campbell
2021-09-05 12:41:13 +01:00
parent fe665a03df
commit 0997de99a2
11 changed files with 203 additions and 6 deletions
+22
View File
@@ -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());