function isa() pour les vclasses
This commit is contained in:
		
							parent
							
								
									9d6e7f3955
								
							
						
					
					
						commit
						4f0d6d40dc
					
				| @ -4,6 +4,11 @@ namespace nulib\php\types; | ||||
| use nulib\cl; | ||||
| 
 | ||||
| class varray { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_array($value); | ||||
|     else return is_scalar($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$array): void { | ||||
|     if (!is_array($array)) $array = cl::with($array); | ||||
|   } | ||||
|  | ||||
| @ -30,6 +30,12 @@ class vbool { | ||||
|     return in_array($value, self::NO_VALUES, true); | ||||
|   } | ||||
| 
 | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_bool($value); | ||||
|     elseif (is_string($value)) return self::is_yes($value) || self::is_no($value); | ||||
|     else return is_scalar($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$bool): void { | ||||
|     if (is_string($bool)) { | ||||
|       if (self::is_yes($bool)) $bool = true; | ||||
|  | ||||
| @ -2,6 +2,11 @@ | ||||
| namespace nulib\php\types; | ||||
| 
 | ||||
| class vcontent { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_array($value) || is_string($value); | ||||
|     else return is_array($value) || is_scalar($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$content): void { | ||||
|     if ($content === null || $content === false) $content = []; | ||||
|     elseif (!is_string($content) && !is_array($content)) $content = strval($content); | ||||
|  | ||||
| @ -2,6 +2,11 @@ | ||||
| namespace nulib\php\types; | ||||
| 
 | ||||
| class vfloat { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_float($value); | ||||
|     else return is_numeric($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$float): void { | ||||
|     if (!is_float($float)) $float = floatval($float); | ||||
|   } | ||||
|  | ||||
| @ -4,6 +4,11 @@ namespace nulib\php\types; | ||||
| use nulib\php\func; | ||||
| 
 | ||||
| class vfunc { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return $value instanceof func; | ||||
|     else return func::is_callable($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$func): void { | ||||
|     $func = func::ensure($func); | ||||
|   } | ||||
|  | ||||
| @ -2,6 +2,11 @@ | ||||
| namespace nulib\php\types; | ||||
| 
 | ||||
| class vint { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_int($value); | ||||
|     else return is_numeric($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$int): void { | ||||
|     if (!is_int($int)) $int = intval($int); | ||||
|   } | ||||
|  | ||||
| @ -2,6 +2,11 @@ | ||||
| namespace nulib\php\types; | ||||
| 
 | ||||
| class vkey { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_int($value) || is_string($value); | ||||
|     else return is_scalar($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$key): void { | ||||
|     if ($key === null) $key = ""; | ||||
|     elseif ($key === false) $key = 0; | ||||
|  | ||||
| @ -2,6 +2,11 @@ | ||||
| namespace nulib\php\types; | ||||
| 
 | ||||
| class vpkey { | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_array($value) || is_int($value) || is_string($value); | ||||
|     else return is_array($value) || is_scalar($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$pkey): void { | ||||
|     if ($pkey === null) $pkey = ""; | ||||
|     elseif ($pkey === false) $pkey = 0; | ||||
|  | ||||
| @ -9,6 +9,11 @@ class vrawstring { | ||||
|   /** @var bool faut-il normaliser les caractères fin de ligne */ | ||||
|   const NORM_NL = false; | ||||
| 
 | ||||
|   static function isa($value, bool $strict=false) : bool { | ||||
|     if ($strict) return is_string($value); | ||||
|     else return is_scalar($value); | ||||
|   } | ||||
| 
 | ||||
|   static function ensure(&$string): void { | ||||
|     if (!is_string($string)) $string = strval($string); | ||||
|     if (static::TRIM) $string = trim($string); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user