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

37 lines
782 B
PHP

<?php
namespace nur\sery\wip\php\access;
use nur\sery\cl;
/**
* Class AbstractAccess: implémentation par défaut pour des instances standard
* de {@link IAccess}
*/
abstract class AbstractAccess implements IAccess {
function inc(): int {
$value = (int)$this->get();
$this->set(++$value);
return $value;
}
function dec(bool $allowNegative=false): int {
$value = (int)$this->get();
if ($allowNegative || $value > 0) {
$this->set(--$value);
}
return $value;
}
function merge(?array $values): void {
$array = $this->get();
$array = cl::merge($array, $values);
$this->set($array);
}
function append($value, $key=null): void {
$array = $this->get();
cl::set($array, $key, $value);
$this->set($array);
}
}