ajout de parse_not
This commit is contained in:
		
							parent
							
								
									8bdd704621
								
							
						
					
					
						commit
						9bff7903a3
					
				| @ -20,18 +20,28 @@ abstract class AbstractReader implements IReader { | |||||||
|   const TRIM = true; |   const TRIM = true; | ||||||
| 
 | 
 | ||||||
|   /** @var bool faut-il considérer les chaines vides comme null? */ |   /** @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? |    * @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 |    * si false, ne forcer le type numérique que si la chaine ne commence pas par | ||||||
|    * i.e "06" est une chaine, alors "63" est un nombre |    * 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; |   const PARSE_NUMERIC = false; | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * @var bool faut-il forcer le type {@link Date} ou {@link DateTime} pour une |    * @var bool faut-il forcer le type {@link Date} ou {@link DateTime} pour une | ||||||
|    * chaine au bon format? |    * chaine au bon format? | ||||||
|  |    * | ||||||
|  |    * ce paramètre est ignoré si PARSE_NOT == true | ||||||
|    */ |    */ | ||||||
|   const PARSE_DATE = true; |   const PARSE_DATE = true; | ||||||
| 
 | 
 | ||||||
| @ -43,7 +53,8 @@ abstract class AbstractReader implements IReader { | |||||||
|     $this->useHeaders = $params["use_headers"] ?? static::USE_HEADERS; |     $this->useHeaders = $params["use_headers"] ?? static::USE_HEADERS; | ||||||
|     $this->input = $params["input"] ?? static::INPUT; |     $this->input = $params["input"] ?? static::INPUT; | ||||||
|     $this->trim = boolval($params["trim"] ?? static::TRIM); |     $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->parseNumeric = boolval($params["parse_numeric"] ?? static::PARSE_NUMERIC); | ||||||
|     $this->parseDate = boolval($params["parse_date"] ?? static::PARSE_DATE); |     $this->parseDate = boolval($params["parse_date"] ?? static::PARSE_DATE); | ||||||
|   } |   } | ||||||
| @ -58,7 +69,9 @@ abstract class AbstractReader implements IReader { | |||||||
| 
 | 
 | ||||||
|   protected bool $trim; |   protected bool $trim; | ||||||
| 
 | 
 | ||||||
|   protected bool $parseEmptyAsNull; |   protected bool $emptyAsNull; | ||||||
|  | 
 | ||||||
|  |   protected bool $parseNot; | ||||||
| 
 | 
 | ||||||
|   protected bool $parseNumeric; |   protected bool $parseNumeric; | ||||||
| 
 | 
 | ||||||
| @ -88,11 +101,11 @@ abstract class AbstractReader implements IReader { | |||||||
|     if ($this->trim && is_string($col)) { |     if ($this->trim && is_string($col)) { | ||||||
|       $col = trim($col); |       $col = trim($col); | ||||||
|     } |     } | ||||||
|     if ($this->parseEmptyAsNull && $col === "") { |     if ($this->emptyAsNull && $col === "") { | ||||||
|       # valeur vide --> null
 |       # valeur vide --> null
 | ||||||
|       $col = null; |       $col = null; | ||||||
|     } |     } | ||||||
|     if (!is_string($col)) return; |     if (!is_string($col) || $this->parseNot) return; | ||||||
|     if ($this->parseDate) { |     if ($this->parseDate) { | ||||||
|       if (DateTime::isa_datetime($col, true)) { |       if (DateTime::isa_datetime($col, true)) { | ||||||
|         # datetime
 |         # datetime
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user