From 97a4b3f6580702ce8c7175d6222f86ab03eac9ca Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Fri, 7 Jan 2022 13:30:09 +0100 Subject: [PATCH] Update serializable interface This should prepare for the future deprecation of the `Serializable` interface. --- src/Entity/User.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Entity/User.php b/src/Entity/User.php index e2f46105e..fd3b8c239 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -247,16 +247,26 @@ public function eraseCredentials(): void */ public function serialize(): string { - return serialize([$this->id, $this->username, $this->password]); + return serialize($this->__serialize()); + } + + public function __serialize(): array + { + return [$this->id, $this->username, $this->password]; } /** * {@inheritdoc} */ public function unserialize($serialized): void + { + $this->__unserialize(unserialize($serialized, ['allowed_classes' => false])); + } + + public function __unserialize(array $data): void { // add $this->salt too if you don't use Bcrypt or Argon2i - [$this->id, $this->username, $this->password] = unserialize($serialized, ['allowed_classes' => false]); + [$this->id, $this->username, $this->password] = $data; } public function getLastseenAt(): ?\DateTimeInterface