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 Iterator;
|
||||
use nulib\os\EOFException;
|
||||
use nulib\DataException;
|
||||
use nulib\php\ICloseable;
|
||||
|
||||
/**
|
||||
|
@ -29,12 +29,12 @@ abstract class AbstractIterator implements Iterator, ICloseable {
|
|||
protected function beforeIter() {}
|
||||
|
||||
/**
|
||||
* retourner le prochain élément. lancer l'exception {@link EOFException} pour
|
||||
* indiquer que plus aucun élément n'est disponible
|
||||
* retourner le prochain élément. lancer l'exception {@link DataException}
|
||||
* pour indiquer que plus aucun élément n'est disponible
|
||||
*
|
||||
* le cas échéant, initialiser $key
|
||||
*
|
||||
* @throws EOFException
|
||||
* @throws DataException
|
||||
*/
|
||||
abstract protected function _next(&$key);
|
||||
|
||||
|
@ -94,7 +94,7 @@ abstract class AbstractIterator implements Iterator, ICloseable {
|
|||
$this->valid = false;
|
||||
try {
|
||||
$item = $this->_next($key);
|
||||
} catch (EOFException $e) {
|
||||
} catch (DataException $e) {
|
||||
$this->beforeClose();
|
||||
try {
|
||||
$this->_teardown();
|
||||
|
|
Loading…
Reference in New Issue