modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-01-01 01:01:27 +04:00
parent 605db70cc5
commit 4b0c79f4c3
5 changed files with 36 additions and 29 deletions

View File

@ -47,4 +47,12 @@ class ref_schema {
"empty" => "{key}: cette valeur ne doit pas être vide", "empty" => "{key}: cette valeur ne doit pas être vide",
"invalid" => "{key}: {orig}: cette valeur est invalide", "invalid" => "{key}: {orig}: cette valeur est invalide",
]; ];
/** @var array meta-schema d'un schéma de nature associative */
const ASSOC_METASCHEMA = [
];
/** @var array meta-schema d'un schéma de nature liste */
const LIST_METASCHEMA = [
];
} }

View File

@ -2,13 +2,18 @@
namespace nur\sery\schema\_assoc; namespace nur\sery\schema\_assoc;
use nulib\cl; use nulib\cl;
use nur\sery\ref\schema\ref_schema;
use nur\sery\schema\_scalar\ScalarValue;
use nur\sery\schema\input\Input; use nur\sery\schema\input\Input;
use nur\sery\schema\Schema; use nur\sery\schema\Schema;
use nur\sery\schema\Value; use nur\sery\schema\Value;
/**
* Class AssocSchema
*/
class AssocSchema extends Schema { class AssocSchema extends Schema {
/** @var array meta-schema d'un schéma de nature tableau associatif */ /** @var array meta-schema d'un schéma de nature tableau associatif */
const METASCHEMA = []; const METASCHEMA = ref_schema::ASSOC_METASCHEMA;
/** /**
* indiquer si $definition est une définition de schéma de nature tableau * indiquer si $definition est une définition de schéma de nature tableau
@ -45,10 +50,8 @@ class AssocSchema extends Schema {
return true; return true;
} }
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): Value { function newValue(?Value &$destv=null, &$dest=null, $destKey=null): AssocValue {
if (!($destv instanceof AssocValue)) $destv = new AssocValue($this); if ($destv instanceof AssocValue) return $destv->reset($dest, $destKey);
if ($dest instanceof Input) $input = $dest; else return ($destv = new AssocValue($this, $dest, $destKey));
else $input = new Input($dest);
return $destv->reset($input, $destKey);
} }
} }

View File

@ -1,12 +1,14 @@
<?php <?php
namespace nur\sery\schema\_list; namespace nur\sery\schema\_list;
use nur\sery\ref\schema\ref_schema;
use nur\sery\schema\_assoc\AssocValue;
use nur\sery\schema\Schema; use nur\sery\schema\Schema;
use nur\sery\schema\Value; use nur\sery\schema\Value;
class ListSchema extends Schema { class ListSchema extends Schema {
/** @var array meta-schema d'un schéma de nature liste */ /** @var array meta-schema d'un schéma de nature liste */
const METASCHEMA = []; const METASCHEMA = ref_schema::LIST_METASCHEMA;
/** /**
* indiquer si $definition est une définition de schéma de nature liste que * indiquer si $definition est une définition de schéma de nature liste que
@ -45,8 +47,8 @@ class ListSchema extends Schema {
return true; return true;
} }
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): Value { function newValue(?Value &$destv=null, &$dest=null, $destKey=null): ListValue {
if (!($destv instanceof ListValue)) $destv = new ListValue($this); if ($destv instanceof ListValue) return $destv->reset($dest, $destKey);
return $destv->reset($dest, $destKey); else return ($destv = new ListValue($this, $dest, $destKey));
} }
} }

View File

@ -39,12 +39,6 @@ use nur\sery\schema\Value;
class ScalarSchema extends Schema { class ScalarSchema extends Schema {
/** @var array meta-schema d'un schéma de nature scalaire */ /** @var array meta-schema d'un schéma de nature scalaire */
const METASCHEMA = ref_schema::SCALAR_METASCHEMA; const METASCHEMA = ref_schema::SCALAR_METASCHEMA;
const METASCHEMA_KEYS = [
"type", "default", "title", "required", "nullable", "desc",
"analyzer_func", "extractor_func", "parser_func", "normalizer_func", "messages",
"formatter_func", "format",
"", "name", "pkey", "header", "composite",
];
/** /**
* indiquer si $definition est une définition de schéma scalaire que * indiquer si $definition est une définition de schéma scalaire que
@ -81,14 +75,14 @@ class ScalarSchema extends Schema {
if (!is_array($definition)) $definition = [$definition]; if (!is_array($definition)) $definition = [$definition];
# s'assurer que toutes les clés existent avec leur valeur par défaut # s'assurer que toutes les clés existent avec leur valeur par défaut
$index = 0; $index = 0;
foreach (self::METASCHEMA_KEYS as $pkey) { foreach (array_keys(self::METASCHEMA) as $key) {
if (!array_key_exists($pkey, $definition)) { if (!array_key_exists($key, $definition)) {
if (array_key_exists($index, $definition)) { if (array_key_exists($index, $definition)) {
$definition[$pkey] = $definition[$index]; $definition[$key] = $definition[$index];
unset($definition[$index]); unset($definition[$index]);
$index++; $index++;
} else { } else {
$definition[$pkey] = self::METASCHEMA[$pkey][1]; $definition[$key] = self::METASCHEMA[$key][1];
} }
} }
} }
@ -96,10 +90,10 @@ class ScalarSchema extends Schema {
if (cl::have_num_keys($definition)) { if (cl::have_num_keys($definition)) {
$keys = array_keys($definition); $keys = array_keys($definition);
$index = 0; $index = 0;
foreach ($keys as $pkey) { foreach ($keys as $key) {
if (!is_int($pkey)) continue; if (!is_int($key)) continue;
$definition[$index] = $definition[$pkey]; $definition[$index] = $definition[$key];
unset($definition[$pkey]); unset($definition[$key]);
$index++; $index++;
} }
} }
@ -180,7 +174,7 @@ class ScalarSchema extends Schema {
return true; return true;
} }
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): Value { function newValue(?Value &$destv=null, &$dest=null, $destKey=null): ScalarValue {
if ($destv instanceof ScalarValue) return $destv->reset($dest, $destKey); if ($destv instanceof ScalarValue) return $destv->reset($dest, $destKey);
else return ($destv = new ScalarValue($this, $dest, $destKey)); else return ($destv = new ScalarValue($this, $dest, $destKey));
} }

View File

@ -63,7 +63,7 @@ class ScalarValue extends Value {
return [null]; return [null];
} }
function getValue($key=null): Value { function getValue($key=null): ScalarValue {
if ($key === null) return $this; if ($key === null) return $this;
throw ValueException::invalid_key($key); throw ValueException::invalid_key($key);
} }
@ -148,7 +148,7 @@ class ScalarValue extends Value {
return $modified; return $modified;
} }
function getResult(): Result { function getResult(): ScalarResult {
return $this->result; return $this->result;
} }
@ -177,7 +177,7 @@ class ScalarValue extends Value {
else return $default; else return $default;
} }
function set($value, ?bool $verifix=null): Value { function set($value, ?bool $verifix=null): ScalarValue {
$this->input->set($value, $this->destKey); $this->input->set($value, $this->destKey);
$this->_analyze(); $this->_analyze();
if ($verifix === null) $verifix = $this->defaultVerifix; if ($verifix === null) $verifix = $this->defaultVerifix;
@ -185,7 +185,7 @@ class ScalarValue extends Value {
return $this; return $this;
} }
function unset(?bool $verifix=null): Value { function unset(?bool $verifix=null): ScalarValue {
$this->input->unset($this->destKey); $this->input->unset($this->destKey);
$this->_analyze(); $this->_analyze();
if ($verifix === null) $verifix = $this->defaultVerifix; if ($verifix === null) $verifix = $this->defaultVerifix;