diff --git a/src/schema/Wrapper.php b/src/schema/Wrapper.php index 4cf6a9a..d8e1e4d 100644 --- a/src/schema/Wrapper.php +++ b/src/schema/Wrapper.php @@ -136,7 +136,7 @@ abstract class Wrapper implements ArrayAccess, IteratorAggregate { /** retourner true si la valeur existe */ function isPresent($key=false): bool { - return $this->getResult()->present; + return $this->getResult($key)->present; } /** retourner le type associé à la valeur */ @@ -146,17 +146,17 @@ abstract class Wrapper implements ArrayAccess, IteratorAggregate { /** retourner true si la valeur est disponible */ function isAvailable($key=false): bool { - return $this->getResult()->available; + return $this->getResult($key)->available; } /** retourner true si la valeur est valide */ function isValid($key=false): bool { - return $this->getResult()->valid; + return $this->getResult($key)->valid; } /** retourner true si la valeur est dans sa forme normalisée */ function isNormalized($key=false): bool { - return $this->getResult()->normalized; + return $this->getResult($key)->normalized; } diff --git a/src/schema/_assoc/AssocSchema.php b/src/schema/_assoc/AssocSchema.php index e49d794..6d3ba16 100644 --- a/src/schema/_assoc/AssocSchema.php +++ b/src/schema/_assoc/AssocSchema.php @@ -85,11 +85,11 @@ class AssocSchema extends Schema { } function getWrapper(&$value=null, $valueKey=null, ?array $params=null, ?Wrapper &$wrapper=null): AssocWrapper { - # si pas de valeur ni de wrapper, pas de vérification et donc pas d'exception - # cf le code similaire dans ScalarWrapper::__construct() - $dontNormalize = $value === null && $wrapper === null; + # si pas de valeur ni de wrapper, pas d'analyse et donc pas d'exception + # cf le code similaire dans AssocWrapper::__construct() + $dontAnalyze = $value === null && $wrapper === null; if (!($wrapper instanceof AssocWrapper)) $wrapper = $this->newWrapper(); if ($params !== null) $wrapper->resetParams($params); - return $wrapper->reset($value, $valueKey, $dontNormalize? ["normalize" => false]: null); + return $wrapper->reset($value, $valueKey, $dontAnalyze? ["analyze" => false]: null); } } diff --git a/src/schema/_scalar/ScalarSchema.php b/src/schema/_scalar/ScalarSchema.php index d726ebb..5c14a5c 100644 --- a/src/schema/_scalar/ScalarSchema.php +++ b/src/schema/_scalar/ScalarSchema.php @@ -89,9 +89,9 @@ class ScalarSchema extends Schema { function getWrapper(&$value=null, $valueKey=null, ?array $params=null, ?Wrapper &$wrapper=null): ScalarWrapper { # si pas de valeur ni de wrapper, pas de vérification et donc pas d'exception # cf le code similaire dans ScalarWrapper::__construct() - $dontNormalize = $value === null && $wrapper === null; + $dontAnalyze = $value === null && $wrapper === null; if (!($wrapper instanceof ScalarWrapper)) $wrapper = $this->newWrapper(); if ($params !== null) $wrapper->resetParams($params); - return $wrapper->reset($value, $valueKey, $dontNormalize? ["normalize" => false]: null); + return $wrapper->reset($value, $valueKey, $dontAnalyze? ["analyze" => false]: null); } } diff --git a/tests/wip/schema/_assoc/AssocSchemaTest.php b/tests/wip/schema/_assoc/AssocSchemaTest.php index a082855..38586bd 100644 --- a/tests/wip/schema/_assoc/AssocSchemaTest.php +++ b/tests/wip/schema/_assoc/AssocSchemaTest.php @@ -98,8 +98,35 @@ class AssocSchemaTest extends TestCase { ], ]), $schema->getDefinition()); //yaml::dump($schema->getDefinition()); + } - $wrapper = $schema->getWrapper(); - $wrapper->getKeys(); + function testWrapper() { + $schema = new AssocSchema([ + "a" => "string", + "b" => "int", + "c" => "bool", + ]); + + $array = ["c" => false, "a" => " string "]; + $schema->getWrapper($array); + self::assertSame([ + "a" => "string", + "b" => null, + "c" => false, + ], $array); + + $array = ["c" => false, "a" => " string "]; + $schema->getWrapper($array, null, ["ensure_order" => false]); + self::assertSame([ + "c" => false, + "a" => "string", + "b" => null, + ], $array); + + $array = ["a" => " string "]; + $schema->getWrapper($array, null, ["ensure_keys" => false]); + self::assertSame([ + "a" => "string", + ], $array); } }