Skip to content

Commit

Permalink
Update serializable interface
Browse files Browse the repository at this point in the history
This should prepare for the future deprecation of the `Serializable` interface.
  • Loading branch information
bobvandevijver authored Jan 7, 2022
1 parent 544e184 commit 97a4b3f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 97a4b3f

Please sign in to comment.