58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
namespace nur\sery\wip\php\access;
|
|
|
|
use nulib\cl;
|
|
|
|
class ChainKeyAccess extends AbstractAccess {
|
|
function __construct(IAccess $access, $key) {
|
|
parent::__construct();
|
|
$this->access = $access;
|
|
$this->key = $key;
|
|
}
|
|
|
|
protected IAccess $access;
|
|
|
|
/** @var int|string|array */
|
|
protected $key;
|
|
|
|
function isAllowEmpty(): bool {
|
|
return $this->access->isAllowEmpty();
|
|
}
|
|
|
|
function exists(): bool {
|
|
$key = $this->key;
|
|
if ($key === null) return false;
|
|
if (!$this->access->exists()) return false;
|
|
return cl::phas($this->access->get(), $key);
|
|
}
|
|
|
|
function available(): bool {
|
|
$key = $this->key;
|
|
if ($key === null) return false;
|
|
if (!$this->access->available()) return false;
|
|
$array = $this->access->get();
|
|
if (!cl::phas($array, $key)) return false;
|
|
return $this->isAllowEmpty() || cl::pget($array, $key) !== "";
|
|
}
|
|
|
|
function get($default=null) {
|
|
return cl::pget($this->access->get($default), $this->key);
|
|
}
|
|
|
|
function set($value): void {
|
|
$array = $this->access->get();
|
|
cl::pset($array, $this->key, $value);
|
|
$this->access->set($array);
|
|
}
|
|
|
|
function del(): void {
|
|
$array = $this->access->get();
|
|
cl::pdel($array, $this->key);
|
|
$this->access->set($array);
|
|
}
|
|
|
|
function addKey($key): IAccess {
|
|
return new ChainKeyAccess($this->access, cl::merge($this->key, $key));
|
|
}
|
|
}
|