From 4b0c79f4c3b9406a0f242eaa3d44361c898b9f01 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 1 Jan 2024 01:01:27 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- src/ref/schema/ref_schema.php | 8 ++++++++ src/schema/_assoc/AssocSchema.php | 15 +++++++++------ src/schema/_list/ListSchema.php | 10 ++++++---- src/schema/_scalar/ScalarSchema.php | 24 +++++++++--------------- src/schema/_scalar/ScalarValue.php | 8 ++++---- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/ref/schema/ref_schema.php b/src/ref/schema/ref_schema.php index 2f0ffbd..8f5561c 100644 --- a/src/ref/schema/ref_schema.php +++ b/src/ref/schema/ref_schema.php @@ -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 = [ + ]; } diff --git a/src/schema/_assoc/AssocSchema.php b/src/schema/_assoc/AssocSchema.php index b6c20a0..3bbb38d 100644 --- a/src/schema/_assoc/AssocSchema.php +++ b/src/schema/_assoc/AssocSchema.php @@ -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)); } } diff --git a/src/schema/_list/ListSchema.php b/src/schema/_list/ListSchema.php index cda899a..ff273e8 100644 --- a/src/schema/_list/ListSchema.php +++ b/src/schema/_list/ListSchema.php @@ -1,12 +1,14 @@ 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)); } } diff --git a/src/schema/_scalar/ScalarSchema.php b/src/schema/_scalar/ScalarSchema.php index 4ca3a7c..ff03d06 100644 --- a/src/schema/_scalar/ScalarSchema.php +++ b/src/schema/_scalar/ScalarSchema.php @@ -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)); } diff --git a/src/schema/_scalar/ScalarValue.php b/src/schema/_scalar/ScalarValue.php index 06b0d86..eb75932 100644 --- a/src/schema/_scalar/ScalarValue.php +++ b/src/schema/_scalar/ScalarValue.php @@ -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;