Skip to content

Commit

Permalink
Merge pull request #105 from schmittjoh/backward-compat-8.1
Browse files Browse the repository at this point in the history
Backward compatible usage of the new __serialize/__deserialize methods
  • Loading branch information
goetas authored Nov 15, 2021
2 parents 3653cd1 + 30a3893 commit 3c5f34f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
"dev-master": "2.x-dev"
}
}
}
36 changes: 18 additions & 18 deletions src/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ public function isFresh(?int $timestamp = null): bool
*/
public function serialize()
{
return serialize($this->__serialize());
return serialize([
$this->name,
$this->methodMetadata,
$this->propertyMetadata,
$this->fileResources,
$this->createdAt,
]);
}

/**
Expand All @@ -96,34 +102,28 @@ public function serialize()
*/
public function unserialize($str)
{
$this->__unserialize((array) unserialize((string) $str));
[
$this->name,
$this->methodMetadata,
$this->propertyMetadata,
$this->fileResources,
$this->createdAt,
] = unserialize($str);
}

/**
* @return array<mixed>
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
*/
public function __serialize(): array
{
return [
$this->name,
$this->methodMetadata,
$this->propertyMetadata,
$this->fileResources,
$this->createdAt,
];
return [$this->serialize()];
}

/**
* @param array<mixed> $data
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*/
public function __unserialize(array $data): void
{
[
$this->name,
$this->methodMetadata,
$this->propertyMetadata,
$this->fileResources,
$this->createdAt,
] = $data;
$this->unserialize($data[0]);
}
}
12 changes: 6 additions & 6 deletions src/MethodMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function invoke(object $obj, array $args = [])
*/
public function serialize()
{
return serialize($this->__serialize());
return serialize([$this->class, $this->name]);
}

/**
Expand All @@ -69,23 +69,23 @@ public function serialize()
*/
public function unserialize($str)
{
$this->__unserialize((array) unserialize((string) $str));
[$this->class, $this->name] = unserialize($str);
}

/**
* @return array<string>
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
*/
public function __serialize(): array
{
return [$this->class, $this->name];
return [$this->serialize()];
}

/**
* @param array<string> $data
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*/
public function __unserialize(array $data): void
{
[$this->class, $this->name] = $data;
$this->unserialize($data[0]);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public function __construct(string $class, string $name)
*/
public function serialize()
{
return serialize($this->__serialize());
return serialize([
$this->class,
$this->name,
]);
}

/**
Expand All @@ -53,25 +56,22 @@ public function serialize()
*/
public function unserialize($str)
{
$this->__unserialize((array) unserialize((string) $str));
[$this->class, $this->name] = unserialize($str);
}

/**
* @return array<string>
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
*/
public function __serialize(): array
{
return [
$this->class,
$this->name,
];
return [$this->serialize()];
}

/**
* @param array<string> $data
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*/
public function __unserialize(array $data): void
{
[$this->class, $this->name] = $data;
$this->unserialize($data[0]);
}
}

0 comments on commit 3c5f34f

Please sign in to comment.