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

36 lines
728 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;
/**
* 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);
}
}