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
+25
View File
@@ -16,10 +16,12 @@ namespace Ramsey\Uuid\Type;
use Ramsey\Uuid\Exception\UnsupportedOperationException;
use Ramsey\Uuid\Type\Integer as IntegerObject;
use ValueError;
use stdClass;
use function json_decode;
use function json_encode;
use function sprintf;
/**
* A value object representing a timestamp
@@ -88,6 +90,17 @@ final class Time implements TypeInterface
return (string) json_encode($this);
}
/**
* @return array{seconds: string, microseconds: string}
*/
public function __serialize(): array
{
return [
'seconds' => $this->getSeconds()->toString(),
'microseconds' => $this->getMicroseconds()->toString(),
];
}
/**
* Constructs the object from a serialized string representation
*
@@ -109,4 +122,16 @@ final class Time implements TypeInterface
$this->__construct($time->seconds, $time->microseconds);
}
/**
* @param array{seconds: string, microseconds: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['seconds']) || !isset($data['microseconds'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->__construct($data['seconds'], $data['microseconds']);
}
}