modifs.mineures sans commentaires
This commit is contained in:
parent
605db70cc5
commit
4b0c79f4c3
|
@ -47,4 +47,12 @@ class ref_schema {
|
|||
"empty" => "{key}: cette valeur ne doit pas être vide",
|
||||
"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 = [
|
||||
];
|
||||
}
|
||||
|
|
|
@ -2,13 +2,18 @@
|
|||
namespace nur\sery\schema\_assoc;
|
||||
|
||||
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\Schema;
|
||||
use nur\sery\schema\Value;
|
||||
|
||||
/**
|
||||
* Class AssocSchema
|
||||
*/
|
||||
class AssocSchema extends Schema {
|
||||
/** @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
|
||||
|
@ -45,10 +50,8 @@ class AssocSchema extends Schema {
|
|||
return true;
|
||||
}
|
||||
|
||||
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): Value {
|
||||
if (!($destv instanceof AssocValue)) $destv = new AssocValue($this);
|
||||
if ($dest instanceof Input) $input = $dest;
|
||||
else $input = new Input($dest);
|
||||
return $destv->reset($input, $destKey);
|
||||
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): AssocValue {
|
||||
if ($destv instanceof AssocValue) return $destv->reset($dest, $destKey);
|
||||
else return ($destv = new AssocValue($this, $dest, $destKey));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
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\Value;
|
||||
|
||||
class ListSchema extends Schema {
|
||||
/** @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
|
||||
|
@ -45,8 +47,8 @@ class ListSchema extends Schema {
|
|||
return true;
|
||||
}
|
||||
|
||||
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): Value {
|
||||
if (!($destv instanceof ListValue)) $destv = new ListValue($this);
|
||||
return $destv->reset($dest, $destKey);
|
||||
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): ListValue {
|
||||
if ($destv instanceof ListValue) return $destv->reset($dest, $destKey);
|
||||
else return ($destv = new ListValue($this, $dest, $destKey));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,6 @@ use nur\sery\schema\Value;
|
|||
class ScalarSchema extends Schema {
|
||||
/** @var array meta-schema d'un schéma de nature scalaire */
|
||||
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
|
||||
|
@ -81,14 +75,14 @@ class ScalarSchema extends Schema {
|
|||
if (!is_array($definition)) $definition = [$definition];
|
||||
# s'assurer que toutes les clés existent avec leur valeur par défaut
|
||||
$index = 0;
|
||||
foreach (self::METASCHEMA_KEYS as $pkey) {
|
||||
if (!array_key_exists($pkey, $definition)) {
|
||||
foreach (array_keys(self::METASCHEMA) as $key) {
|
||||
if (!array_key_exists($key, $definition)) {
|
||||
if (array_key_exists($index, $definition)) {
|
||||
$definition[$pkey] = $definition[$index];
|
||||
$definition[$key] = $definition[$index];
|
||||
unset($definition[$index]);
|
||||
$index++;
|
||||
} 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)) {
|
||||
$keys = array_keys($definition);
|
||||
$index = 0;
|
||||
foreach ($keys as $pkey) {
|
||||
if (!is_int($pkey)) continue;
|
||||
$definition[$index] = $definition[$pkey];
|
||||
unset($definition[$pkey]);
|
||||
foreach ($keys as $key) {
|
||||
if (!is_int($key)) continue;
|
||||
$definition[$index] = $definition[$key];
|
||||
unset($definition[$key]);
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +174,7 @@ class ScalarSchema extends Schema {
|
|||
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);
|
||||
else return ($destv = new ScalarValue($this, $dest, $destKey));
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ class ScalarValue extends Value {
|
|||
return [null];
|
||||
}
|
||||
|
||||
function getValue($key=null): Value {
|
||||
function getValue($key=null): ScalarValue {
|
||||
if ($key === null) return $this;
|
||||
throw ValueException::invalid_key($key);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class ScalarValue extends Value {
|
|||
return $modified;
|
||||
}
|
||||
|
||||
function getResult(): Result {
|
||||
function getResult(): ScalarResult {
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ class ScalarValue extends Value {
|
|||
else return $default;
|
||||
}
|
||||
|
||||
function set($value, ?bool $verifix=null): Value {
|
||||
function set($value, ?bool $verifix=null): ScalarValue {
|
||||
$this->input->set($value, $this->destKey);
|
||||
$this->_analyze();
|
||||
if ($verifix === null) $verifix = $this->defaultVerifix;
|
||||
|
@ -185,7 +185,7 @@ class ScalarValue extends Value {
|
|||
return $this;
|
||||
}
|
||||
|
||||
function unset(?bool $verifix=null): Value {
|
||||
function unset(?bool $verifix=null): ScalarValue {
|
||||
$this->input->unset($this->destKey);
|
||||
$this->_analyze();
|
||||
if ($verifix === null) $verifix = $this->defaultVerifix;
|
||||
|
|
Loading…
Reference in New Issue