36 lines
728 B
PHP
36 lines
728 B
PHP
|
<?php
|
||
|
namespace nur\sery\wip\php\access;
|
||
|
|
||
|
use nur\sery\cl;
|
||
|
|
||
|
/**
|
||
|
* Class KeyAccess: accès à une valeur d'un tableau
|
||
|
*/
|
||
|
class KeyAccess extends AbstractAccess {
|
||
|
function __construct($key) {
|
||
|
$this->key = $key;
|
||
|
}
|
||
|
|
||
|
/** @var int|string */
|
||
|
protected $key;
|
||
|
|
||
|
function exists($src): bool {
|
||
|
return $this->key !== null && cl::has($src, $this->key);
|
||
|
}
|
||
|
|
||
|
function get($src, $default=null) {
|
||
|
if ($this->key === null) return $default;
|
||
|
return cl::get($src, $this->key, $default);
|
||
|
}
|
||
|
|
||
|
function set($value, &$dest): void {
|
||
|
if ($this->key === null) return;
|
||
|
cl::set($dest, $this->key, $value);
|
||
|
}
|
||
|
|
||
|
function del(&$dest): void {
|
||
|
if ($this->key === null) return;
|
||
|
cl::del($dest, $this->key);
|
||
|
}
|
||
|
}
|