fe78426a5d
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
100 lines
1.8 KiB
PHP
100 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXF\Resource\Range;
|
|
|
|
class RangeTally extends Range implements IRangeTally {
|
|
|
|
protected RangeAnchorType $anchor = RangeAnchorType::ABSOLUTE;
|
|
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
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function type(): RangeType {
|
|
return RangeType::TALLY;
|
|
}
|
|
|
|
/**
|
|
* Gets the anchor type of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getAnchor(): RangeAnchorType {
|
|
return $this->anchor;
|
|
}
|
|
|
|
/**
|
|
* Sets the anchor type of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setAnchor(RangeAnchorType $value): void {
|
|
$this->anchor = $value;
|
|
}
|
|
|
|
/**
|
|
* Gets the start position of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getPosition(): string|int {
|
|
return $this->position;
|
|
}
|
|
|
|
/**
|
|
* Sets the start position of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setPosition(string|int $value): void {
|
|
$this->position = $value;
|
|
}
|
|
|
|
/**
|
|
* Gets the count of items in the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getTally(): int {
|
|
return $this->tally;
|
|
}
|
|
|
|
/**
|
|
* Sets the count of items in the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setTally(int $value): void {
|
|
$this->tally = $value;
|
|
}
|
|
|
|
}
|