modifs.mineures sans commentaires
This commit is contained in:
parent
948b94c5cd
commit
b0f5de5e9f
@ -4,11 +4,21 @@ namespace nulib\php\types;
|
||||
use nulib\cl;
|
||||
|
||||
class varray {
|
||||
static function ensure_array(&$array): void {
|
||||
static function ensure(&$array): void {
|
||||
if (!is_array($array)) $array = cl::with($array);
|
||||
}
|
||||
|
||||
static function ensure_narray(&$array): void {
|
||||
if ($array !== null) varray::ensure_array($array);
|
||||
static function ensuren(&$array): void {
|
||||
if ($array !== null) varray::ensure($array);
|
||||
}
|
||||
|
||||
static function with($value): array {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function withn($value): ?array {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class vbool {
|
||||
return in_array($value, self::NO_VALUES, true);
|
||||
}
|
||||
|
||||
static function ensure_bool(&$bool): void {
|
||||
static function ensure(&$bool): void {
|
||||
if (is_string($bool)) {
|
||||
if (self::is_yes($bool)) $bool = true;
|
||||
elseif (self::is_no($bool)) $bool = false;
|
||||
@ -40,7 +40,17 @@ class vbool {
|
||||
if (!is_bool($bool)) $bool = boolval($bool);
|
||||
}
|
||||
|
||||
static function ensure_nbool(&$bool): void {
|
||||
if ($bool !== null) self::ensure_bool($bool);
|
||||
static function ensuren(&$bool): void {
|
||||
if ($bool !== null) self::ensure($bool);
|
||||
}
|
||||
|
||||
static function with($value): bool {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function withn($value): ?bool {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,24 @@
|
||||
namespace nulib\php\types;
|
||||
|
||||
class vcontent {
|
||||
static function ensure_content(&$content): void {
|
||||
static function ensure(&$content): void {
|
||||
if ($content === null || $content === false) $content = [];
|
||||
elseif (!is_string($content) && !is_array($content)) $content = strval($content);
|
||||
}
|
||||
|
||||
static function ensure_ncontent(&$content): void {
|
||||
if ($content !== null) self::ensure_content($content);
|
||||
static function ensuren(&$content): void {
|
||||
if ($content !== null) self::ensure($content);
|
||||
}
|
||||
|
||||
/** @return string|array */
|
||||
static function with($value) {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/** @return string|array|null */
|
||||
static function withn($value) {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,21 @@
|
||||
namespace nulib\php\types;
|
||||
|
||||
class vfloat {
|
||||
static function ensure_float(&$float): void {
|
||||
static function ensure(&$float): void {
|
||||
if (!is_float($float)) $float = floatval($float);
|
||||
}
|
||||
|
||||
static function ensure_nfloat(&$float): void {
|
||||
if ($float !== null) self::ensure_float($float);
|
||||
static function ensuren(&$float): void {
|
||||
if ($float !== null) self::ensure($float);
|
||||
}
|
||||
|
||||
static function with($value): float {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function withn($value): ?float {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,19 @@ namespace nulib\php\types;
|
||||
use nulib\php\func;
|
||||
|
||||
class vfunc {
|
||||
static function ensure_func(&$func): void {
|
||||
static function ensure(&$func): void {
|
||||
$func = func::ensure($func);
|
||||
}
|
||||
|
||||
static function ensure_nfunc(&$func): void {
|
||||
if ($func !== null) self::ensure_func($func);
|
||||
static function ensuren(&$func): void {
|
||||
if ($func !== null) $func = func::ensure($func);
|
||||
}
|
||||
|
||||
static function with($value): func {
|
||||
return func::with($value);
|
||||
}
|
||||
|
||||
static function withn($value): ?func {
|
||||
return func::withn($value);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,21 @@
|
||||
namespace nulib\php\types;
|
||||
|
||||
class vint {
|
||||
static function ensure_int(&$int): void {
|
||||
static function ensure(&$int): void {
|
||||
if (!is_int($int)) $int = intval($int);
|
||||
}
|
||||
|
||||
static function ensure_nint(&$int): void {
|
||||
if ($int !== null) self::ensure_int($int);
|
||||
static function ensuren(&$int): void {
|
||||
if ($int !== null) self::ensure($int);
|
||||
}
|
||||
|
||||
static function with($value): int {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function withn($value): ?int {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,25 @@
|
||||
namespace nulib\php\types;
|
||||
|
||||
class vkey {
|
||||
static function ensure_key(&$key): void {
|
||||
static function ensure(&$key): void {
|
||||
if ($key === null) $key = "";
|
||||
elseif ($key === false) $key = 0;
|
||||
elseif (!is_string($key) && !is_int($key)) $key = strval($key);
|
||||
}
|
||||
|
||||
static function ensure_nkey(&$key): void {
|
||||
if ($key !== null) self::ensure_key($key);
|
||||
static function ensuren(&$key): void {
|
||||
if ($key !== null) self::ensure($key);
|
||||
}
|
||||
|
||||
/** @return string|int */
|
||||
static function with($value) {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/** @return string|int|null */
|
||||
static function withn($value) {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,31 @@
|
||||
namespace nulib\php\types;
|
||||
|
||||
class vpkey {
|
||||
static function ensure_pkey(&$pkey): void {
|
||||
static function ensure(&$pkey): void {
|
||||
if ($pkey === null) $pkey = "";
|
||||
elseif ($pkey === false) $pkey = 0;
|
||||
elseif (!is_string($pkey) && !is_int($pkey) && !is_array($pkey)) $pkey = strval($pkey);
|
||||
if (is_array($pkey)) {
|
||||
foreach ($pkey as &$key) {
|
||||
vkey::ensure_key($key);
|
||||
vkey::ensure($key);
|
||||
};
|
||||
unset($key);
|
||||
}
|
||||
}
|
||||
|
||||
static function ensure_npkey(&$pkey): void {
|
||||
if ($pkey !== null) self::ensure_pkey($pkey);
|
||||
static function ensuren(&$pkey): void {
|
||||
if ($pkey !== null) self::ensure($pkey);
|
||||
}
|
||||
|
||||
/** @return string|int|array */
|
||||
static function with($value) {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/** @return string|int|array|null */
|
||||
static function withn($value) {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,23 @@ class vrawstring {
|
||||
/** @var bool faut-il normaliser les caractères fin de ligne */
|
||||
const NORM_NL = false;
|
||||
|
||||
static function ensure_string(&$string): void {
|
||||
static function ensure(&$string): void {
|
||||
if (!is_string($string)) $string = strval($string);
|
||||
if (static::TRIM) $string = trim($string);
|
||||
if (static::NORM_NL) $string = str::norm_nl($string);
|
||||
}
|
||||
|
||||
static function ensure_nstring(&$string): void {
|
||||
if ($string !== null) self::ensure_string($string);
|
||||
static function ensuren(&$string): void {
|
||||
if ($string !== null) self::ensure($string);
|
||||
}
|
||||
|
||||
static function with($value): string {
|
||||
self::ensure($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function withn($value): ?string {
|
||||
self::ensuren($value);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,5 @@ namespace nulib\php\types;
|
||||
|
||||
class vtext extends vrawstring {
|
||||
const TRIM = true;
|
||||
|
||||
const NORM_NL = true;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ abstract class Schema implements ArrayAccess {
|
||||
$definition["nullable"] = $nullable;
|
||||
# nature
|
||||
$nature = $definition[""];
|
||||
varray::ensure_array($nature);
|
||||
varray::ensure($nature);
|
||||
$natureMetaschema ??= ref_schema::NATURE_METASCHEMA;
|
||||
foreach (array_keys($natureMetaschema) as $key) {
|
||||
if (!array_key_exists($key, $nature)) {
|
||||
@ -196,7 +196,7 @@ abstract class Schema implements ArrayAccess {
|
||||
$header = $definition["header"];
|
||||
if ($name === null) $name = $definitionKey;
|
||||
trawstring::ensure_nstring($name);
|
||||
vpkey::ensure_npkey($pkey);
|
||||
vpkey::ensuren($pkey);
|
||||
trawstring::ensure_nstring($header);
|
||||
if ($pkey === null) $pkey = $name;
|
||||
if ($header === null) $header = $name;
|
||||
@ -204,18 +204,18 @@ abstract class Schema implements ArrayAccess {
|
||||
$definition["pkey"] = $pkey;
|
||||
$definition["header"] = $header;
|
||||
# autres éléments
|
||||
varray::ensure_narray($definition["schema"]);
|
||||
varray::ensuren($definition["schema"]);
|
||||
trawstring::ensure_nstring($definition["title"]);
|
||||
vbool::ensure_bool($definition["required"]);
|
||||
vbool::ensure_bool($definition["nullable"]);
|
||||
vcontent::ensure_ncontent($definition["desc"]);
|
||||
vfunc::ensure_nfunc($definition["analyzer_func"]);
|
||||
vfunc::ensure_nfunc($definition["extractor_func"]);
|
||||
vfunc::ensure_nfunc($definition["parser_func"]);
|
||||
vfunc::ensure_nfunc($definition["normalizer_func"]);
|
||||
varray::ensure_narray($definition["messages"]);
|
||||
vfunc::ensure_nfunc($definition["formatter_func"]);
|
||||
vbool::ensure_nbool($definition["computed"]);
|
||||
vbool::ensure($definition["required"]);
|
||||
vbool::ensure($definition["nullable"]);
|
||||
vcontent::ensuren($definition["desc"]);
|
||||
vfunc::ensuren($definition["analyzer_func"]);
|
||||
vfunc::ensuren($definition["extractor_func"]);
|
||||
vfunc::ensuren($definition["parser_func"]);
|
||||
vfunc::ensuren($definition["normalizer_func"]);
|
||||
varray::ensuren($definition["messages"]);
|
||||
vfunc::ensuren($definition["formatter_func"]);
|
||||
vbool::ensuren($definition["computed"]);
|
||||
|
||||
switch ($nature[0] ?? null) {
|
||||
case "assoc":
|
||||
|
Loading…
x
Reference in New Issue
Block a user