Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Various fixes for PHP 8.1 compatibility #106

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/CredentialRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,41 @@ public static function fromArray(array $credentials, string $memberID): self
return $new;
}

public function __serialize(): array
{
return [
'memberID' => $this->memberID,
'credentials' => $this->toArray()
];
}

public function __unserialize(array $data): void
{
$this->memberID = $data['memberID'];
$this->setCredentials($data['credentials']);
}

/**
* The __serialize() magic method will be automatically used instead of this
*
* @return string
* @deprecated will be removed in 5.0
*/
public function serialize()
{
return json_encode(['credentials' => $this->toArray(), 'memberID' => $this->memberID]);
return json_encode($this->__serialize());
}

/**
* The __unserialize() magic method will be automatically used instead of this almost all the time
* This method will be automatically used if existing serialized data was not saved as an associative array
* and the PHP version used in less than PHP 9.0
*
* @param string $serialized
* @deprecated will be removed in 5.0
*/
public function unserialize($serialized)
{
$raw = json_decode($serialized, true);

$this->memberID = $raw['memberID'];
$this->setCredentials($raw['credentials']);
$this->__unserialize(json_decode($serialized, true));
}
}