nur-sery/nur_src/b/coll/TIterableArray.php

28 lines
731 B
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\b\coll;
/**
* Trait TIterableArray: implémentation des méthodes de base pour être un objet
* array-like itérable. Ce trait doit être utilisé conjointement à
* {@link TBaseArray}
*/
trait TIterableArray {
private $valid;
function _key() { return key($this->data); }
function _current() { return current($this->data); }
function rewind() {
if ($this->data === null) {
$this->valid = false;
} else {
$first = reset($this->data);
$this->valid = $first !== false || key($this->data) !== null;
}
}
function next() {
$next = next($this->data);
$this->valid = $next !== false || key($this->data) !== null;
}
function valid() { return $this->valid; }
}