feat: remove deprecated Serializable interface

This commit is contained in:
Ben Ramsey
2022-04-01 16:40:08 -05:00
parent 13edf70fc9
commit dec678d60b
19 changed files with 217 additions and 361 deletions
+10 -33
View File
@@ -253,38 +253,29 @@ class Uuid implements Rfc4122UuidInterface
return $this->toString();
}
/**
* Converts the UUID to a string for PHP serialization
*/
public function serialize(): string
{
return $this->getFields()->getBytes();
}
/**
* @return array{bytes: string}
*/
public function __serialize(): array
{
return ['bytes' => $this->serialize()];
return ['bytes' => $this->getFields()->getBytes()];
}
/**
* Re-constructs the object from its serialized form
*
* @param string $serialized The serialized PHP string to unserialize into
* a UuidInterface instance
*
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param array{bytes?: string} $data
*/
public function unserialize($serialized): void
public function __unserialize(array $data): void
{
if (strlen($serialized) === 16) {
if (!isset($data['bytes'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
if (strlen($data['bytes']) === 16) {
/** @var Uuid $uuid */
$uuid = self::getFactory()->fromBytes($serialized);
$uuid = self::getFactory()->fromBytes($data['bytes']);
} else {
/** @var Uuid $uuid */
$uuid = self::getFactory()->fromString($serialized);
$uuid = self::getFactory()->fromString($data['bytes']);
}
$this->codec = $uuid->codec;
@@ -293,20 +284,6 @@ class Uuid implements Rfc4122UuidInterface
$this->timeConverter = $uuid->timeConverter;
}
/**
* @param array{bytes: string} $data
*/
public function __unserialize(array $data): void
{
// @codeCoverageIgnoreStart
if (!isset($data['bytes'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
// @codeCoverageIgnoreEnd
$this->unserialize($data['bytes']);
}
public function compareTo(UuidInterface $other): int
{
$compare = strcmp($this->toString(), $other->toString());