20 lines
466 B
PHP
20 lines
466 B
PHP
|
<?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();
|
||
|
}
|
||
|
}
|