feat: add deserilazation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -15,6 +15,24 @@ class RangeTally extends Range implements IRangeTally {
|
||||
protected string|int $position = 0;
|
||||
protected int $tally = 32;
|
||||
|
||||
public function jsonDeserialize(array|string $data): static {
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
if (isset($data['anchor'])) {
|
||||
$this->setAnchor(RangeAnchorType::from($data['anchor']));
|
||||
}
|
||||
if (isset($data['position'])) {
|
||||
$this->setPosition($data['position']);
|
||||
}
|
||||
if (isset($data['tally'])) {
|
||||
$this->setTally($data['tally']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the range
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user