40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
namespace nur\b\coll;
|
|
|
|
/**
|
|
* Trait TGenericArray: méthodes supplémentaires à utiliser avec les traits
|
|
* {@link TBaseArray} et {@link TIterableArray} pour que l'objet soit utilisable
|
|
*
|
|
*/
|
|
trait TGenericArray {
|
|
# ArrayAccess
|
|
function has($key): bool { return $this->_has($key); }
|
|
function &get($key, $default=null) { return $this->_get($key, $default); }
|
|
function set($key, $value): IArray { return $this->_set($key, $value); }
|
|
function add($value): IArray { return $this->_set(null, $value); }
|
|
function del($key): IArray { return $this->_del($key); }
|
|
# Iterator
|
|
function key() { return $this->_key(); }
|
|
function current() { return $this->_current(); }
|
|
|
|
function addAll(?array $values): IArray {
|
|
if ($values !== null) {
|
|
$index = 0;
|
|
foreach ($values as $key => $value) {
|
|
if ($key === $index) {
|
|
$this->add($value);
|
|
$index++;
|
|
} else {
|
|
$this->set($key, $value);
|
|
}
|
|
}
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
function resetAll(?array $values): IArray {
|
|
$this->data = [];
|
|
return $this->addAll($values);
|
|
}
|
|
}
|