Skip to content

Commit

Permalink
Add magic methods for serialization
Browse files Browse the repository at this point in the history
Makes this package usable with PHP 7.4 and higher.
  • Loading branch information
tvdijen authored Oct 23, 2023
1 parent 425c941 commit c18a4c9
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,46 @@ public function unserialize($serialized)

parent::unserialize($parent);
}

/**
* Returns all the necessary state of the object for serialization purposes.
*
* There is no need to serialize any entry, they should be returned as-is.
* If you extend this method, keep in mind you MUST guarantee parent data is present in the state.
* Here is an example of how to extend this method:
* <code>
* public function __serialize(): array
* {
* return [$this->childAttribute, parent::__serialize()];
* }
* </code>
*
* @see __unserialize()
*/
public function __serialize(): array
{
return [$this->assertion, $this->loa, parent::__serialize()];
}

/**
* Restores the object state from an array given by __serialize().
*
* There is no need to unserialize any entry in $data, they are already ready-to-use.
* If you extend this method, keep in mind you MUST pass the parent data to its respective class.
* Here is an example of how to extend this method:
* <code>
* public function __unserialize(array $data): void
* {
* [$this->childAttribute, $parentData] = $data;
* parent::__unserialize($parentData);
* }
* </code>
*
* @see __serialize()
*/
public function __unserialize(array $data): void
{
[$this->assertion, $this->loa, $parentData] = $data;
parent::__unserialize($parentData);
}
}

0 comments on commit c18a4c9

Please sign in to comment.