Skip to content

Commit

Permalink
Merge pull request #101 from W0rma/php81
Browse files Browse the repository at this point in the history
Fix compatibility with PHP 8.1
  • Loading branch information
goetas authored Oct 6, 2021
2 parents a995e6c + b058ef8 commit 3e1dc95
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
steps:
- uses: actions/checkout@v2
- name: Validate composer.json and composer.lock
Expand Down Expand Up @@ -46,6 +47,7 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
steps:
- uses: actions/checkout@v2

Expand Down
1 change: 1 addition & 0 deletions src/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function load(string $class): ?ClassMetadata
if ($metadata instanceof ClassMetadata) {
return $metadata;
}

// if the file does not return anything, the return value is integer `1`.
} catch (\Error $e) {
// ignore corrupted cache
Expand Down
32 changes: 24 additions & 8 deletions src/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ public function isFresh(?int $timestamp = null): bool
*/
public function serialize()
{
return serialize([
$this->name,
$this->methodMetadata,
$this->propertyMetadata,
$this->fileResources,
$this->createdAt,
]);
return serialize($this->__serialize());
}

/**
Expand All @@ -101,13 +95,35 @@ public function serialize()
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation
*/
public function unserialize($str)
{
$this->__unserialize((array) unserialize((string) $str));
}

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

/**
* @param array<mixed> $data
*/
public function __unserialize(array $data): void
{
[
$this->name,
$this->methodMetadata,
$this->propertyMetadata,
$this->fileResources,
$this->createdAt,
] = unserialize($str);
] = $data;
}
}
20 changes: 18 additions & 2 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->class, $this->name]);
return serialize($this->__serialize());
}

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

/**
* @return array<string>
*/
public function __serialize(): array
{
return [$this->class, $this->name];
}

/**
* @param array<string> $data
*/
public function __unserialize(array $data): void
{
[$this->class, $this->name] = $data;
}

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

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

/**
* @return array<string>
*/
public function __serialize(): array
{
return [
$this->class,
$this->name,
];
}

/**
* @param array<string> $data
*/
public function __unserialize(array $data): void
{
[$this->class, $this->name] = $data;
}
}

0 comments on commit 3e1dc95

Please sign in to comment.