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