feat: add deserilazation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,7 +9,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace KTXF\Resource\Range;
|
namespace KTXF\Resource\Range;
|
||||||
|
|
||||||
interface IRange {
|
use KTXF\Json\JsonDeserializable;
|
||||||
|
|
||||||
|
interface IRange extends JsonDeserializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of this range
|
* Gets the type of this range
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ namespace KTXF\Resource\Range;
|
|||||||
|
|
||||||
class Range implements IRange {
|
class Range implements IRange {
|
||||||
|
|
||||||
|
public function jsonDeserialize(array|string $data): static {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the range
|
* Returns the type of the range
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace KTXF\Resource\Range;
|
namespace KTXF\Resource\Range;
|
||||||
|
|
||||||
use DateTime;
|
use DateTimeImmutable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
|
||||||
class RangeDate extends Range implements IRangeDate {
|
class RangeDate extends Range implements IRangeDate {
|
||||||
@@ -17,6 +17,21 @@ class RangeDate extends Range implements IRangeDate {
|
|||||||
protected DateTimeInterface $start;
|
protected DateTimeInterface $start;
|
||||||
protected DateTimeInterface $end;
|
protected DateTimeInterface $end;
|
||||||
|
|
||||||
|
public function jsonDeserialize(array|string $data): static {
|
||||||
|
if (is_string($data)) {
|
||||||
|
$data = json_decode($data, true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data['start'])) {
|
||||||
|
$this->setStart(new DateTimeImmutable($data['start']));
|
||||||
|
}
|
||||||
|
if (isset($data['end'])) {
|
||||||
|
$this->setEnd(new DateTimeImmutable($data['end']));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the range
|
* Returns the type of the range
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,6 +15,24 @@ class RangeTally extends Range implements IRangeTally {
|
|||||||
protected string|int $position = 0;
|
protected string|int $position = 0;
|
||||||
protected int $tally = 32;
|
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
|
* Returns the type of the range
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user