ajout de parse_not

This commit is contained in:
Jephté Clain 2024-10-14 17:19:23 +04:00
parent 8bdd704621
commit 9bff7903a3

View File

@ -20,18 +20,28 @@ abstract class AbstractReader implements IReader {
const TRIM = true;
/** @var bool faut-il considérer les chaines vides comme null? */
const PARSE_EMPTY_AS_NULL = true;
const EMPTY_AS_NULL = true;
/**
* @var bool ne pas essayer de deviner le format des données: les laisser au
* format chaine.
*/
const PARSE_NOT = false;
/**
* @var bool faut-il forcer le type numérique pour une chaine numérique?
* si false, ne forcer le type numérique que si la chaine ne commence pas zéro
* i.e "06" est une chaine, alors "63" est un nombre
* si false, ne forcer le type numérique que si la chaine ne commence pas par
* zéro i.e "06" est une chaine, alors "63" est un nombre
*
* ce paramètre est ignoré si PARSE_NOT == true
*/
const PARSE_NUMERIC = false;
/**
* @var bool faut-il forcer le type {@link Date} ou {@link DateTime} pour une
* chaine au bon format?
*
* ce paramètre est ignoré si PARSE_NOT == true
*/
const PARSE_DATE = true;
@ -43,7 +53,8 @@ abstract class AbstractReader implements IReader {
$this->useHeaders = $params["use_headers"] ?? static::USE_HEADERS;
$this->input = $params["input"] ?? static::INPUT;
$this->trim = boolval($params["trim"] ?? static::TRIM);
$this->parseEmptyAsNull = boolval($params["empty_as_null"] ?? static::PARSE_EMPTY_AS_NULL);
$this->emptyAsNull = boolval($params["empty_as_null"] ?? static::EMPTY_AS_NULL);
$this->parseNot = boolval($params["parse_not"] ?? static::PARSE_NOT);
$this->parseNumeric = boolval($params["parse_numeric"] ?? static::PARSE_NUMERIC);
$this->parseDate = boolval($params["parse_date"] ?? static::PARSE_DATE);
}
@ -58,7 +69,9 @@ abstract class AbstractReader implements IReader {
protected bool $trim;
protected bool $parseEmptyAsNull;
protected bool $emptyAsNull;
protected bool $parseNot;
protected bool $parseNumeric;
@ -88,11 +101,11 @@ abstract class AbstractReader implements IReader {
if ($this->trim && is_string($col)) {
$col = trim($col);
}
if ($this->parseEmptyAsNull && $col === "") {
if ($this->emptyAsNull && $col === "") {
# valeur vide --> null
$col = null;
}
if (!is_string($col)) return;
if (!is_string($col) || $this->parseNot) return;
if ($this->parseDate) {
if (DateTime::isa_datetime($col, true)) {
# datetime