modifs.mineures sans commentaires
This commit is contained in:
parent
eead65706d
commit
01ed9758d5
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
namespace nulib;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DataException: exception générique concernant l'accès à des données
|
||||||
|
*/
|
||||||
|
class DataException extends RuntimeException {
|
||||||
|
static final function no_more_data(): self {
|
||||||
|
return new self("no more data");
|
||||||
|
}
|
||||||
|
|
||||||
|
static final function ensure_not_eof($data, bool $throw=true, $eof=false) {
|
||||||
|
if (!$throw) return null;
|
||||||
|
elseif ($data !== $eof) return $data;
|
||||||
|
else throw self::no_more_data();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ namespace nulib\php\iter;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Iterator;
|
use Iterator;
|
||||||
use nulib\os\EOFException;
|
use nulib\DataException;
|
||||||
use nulib\php\ICloseable;
|
use nulib\php\ICloseable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +29,12 @@ abstract class AbstractIterator implements Iterator, ICloseable {
|
||||||
protected function beforeIter() {}
|
protected function beforeIter() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retourner le prochain élément. lancer l'exception {@link EOFException} pour
|
* retourner le prochain élément. lancer l'exception {@link DataException}
|
||||||
* indiquer que plus aucun élément n'est disponible
|
* pour indiquer que plus aucun élément n'est disponible
|
||||||
*
|
*
|
||||||
* le cas échéant, initialiser $key
|
* le cas échéant, initialiser $key
|
||||||
*
|
*
|
||||||
* @throws EOFException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
abstract protected function _next(&$key);
|
abstract protected function _next(&$key);
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ abstract class AbstractIterator implements Iterator, ICloseable {
|
||||||
$this->valid = false;
|
$this->valid = false;
|
||||||
try {
|
try {
|
||||||
$item = $this->_next($key);
|
$item = $this->_next($key);
|
||||||
} catch (EOFException $e) {
|
} catch (DataException $e) {
|
||||||
$this->beforeClose();
|
$this->beforeClose();
|
||||||
try {
|
try {
|
||||||
$this->_teardown();
|
$this->_teardown();
|
||||||
|
|
Loading…
Reference in New Issue