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
+23
View File
@@ -14,7 +14,10 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Fields;
use ValueError;
use function base64_decode;
use function sprintf;
use function strlen;
/**
@@ -42,6 +45,14 @@ trait SerializableFieldsTrait
return $this->getBytes();
}
/**
* @return array{bytes: string}
*/
public function __serialize(): array
{
return ['bytes' => $this->getBytes()];
}
/**
* Constructs the object from a serialized string representation
*
@@ -58,4 +69,16 @@ trait SerializableFieldsTrait
$this->__construct(base64_decode($serialized));
}
}
/**
* @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']);
}
}