Skip to content

Commit

Permalink
Improved Object serialize()/unserialize()
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Feb 22, 2018
1 parent e533024 commit 274c701
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions system/src/Grav/Framework/Object/Base/ObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public function unserialize($serialized)
{
$data = unserialize($serialized);

if (method_exists($this, 'initObjectProperties')) {
$this->initObjectProperties();
}
$this->doUnserialize($data);
}

Expand All @@ -126,6 +129,10 @@ public function unserialize($serialized)
*/
protected function doUnserialize(array $serialized)
{
if (!isset($serialized['key'], $serialized['type'], $serialized['elements']) || $serialized['type'] !== $this->getType()) {
throw new \InvalidArgumentException("Cannot unserialize '{$this->getType()}': Bad data");
}

$this->setKey($serialized['key']);
$this->setElements($serialized['elements']);
}
Expand Down

0 comments on commit 274c701

Please sign in to comment.