nur-sery/wip/php/access/AbstractAccess.php

33 lines
671 B
PHP
Raw Normal View History

2024-08-17 17:03:07 +04:00
<?php
namespace nur\sery\wip\php\access;
use nur\sery\cl;
abstract class AbstractAccess implements IAccess {
2024-08-17 18:11:11 +04:00
function inc(): int {
$value = (int)$this->get();
$this->set(++$value);
2024-08-17 17:03:07 +04:00
return $value;
}
2024-08-17 18:11:11 +04:00
function dec(bool $allowNegative=false): int {
$value = (int)$this->get();
2024-08-17 17:03:07 +04:00
if ($allowNegative || $value > 0) {
2024-08-17 18:11:11 +04:00
$this->set(--$value);
2024-08-17 17:03:07 +04:00
}
return $value;
}
2024-08-17 18:11:11 +04:00
function merge(?array $values): void {
$array = $this->get();
2024-08-17 17:03:07 +04:00
$array = cl::merge($array, $values);
2024-08-17 18:11:11 +04:00
$this->set($array);
2024-08-17 17:03:07 +04:00
}
2024-08-17 18:11:11 +04:00
function append($value, $key=null): void {
$array = $this->get();
2024-08-17 17:03:07 +04:00
cl::set($array, $key, $value);
2024-08-17 18:11:11 +04:00
$this->set($array);
2024-08-17 17:03:07 +04:00
}
}