modifs.mineures sans commentaires
This commit is contained in:
parent
b9e91bd917
commit
62fc315b9e
@ -136,7 +136,7 @@ abstract class Wrapper implements ArrayAccess, IteratorAggregate {
|
|||||||
|
|
||||||
/** retourner true si la valeur existe */
|
/** retourner true si la valeur existe */
|
||||||
function isPresent($key=false): bool {
|
function isPresent($key=false): bool {
|
||||||
return $this->getResult()->present;
|
return $this->getResult($key)->present;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** retourner le type associé à la valeur */
|
/** retourner le type associé à la valeur */
|
||||||
@ -146,17 +146,17 @@ abstract class Wrapper implements ArrayAccess, IteratorAggregate {
|
|||||||
|
|
||||||
/** retourner true si la valeur est disponible */
|
/** retourner true si la valeur est disponible */
|
||||||
function isAvailable($key=false): bool {
|
function isAvailable($key=false): bool {
|
||||||
return $this->getResult()->available;
|
return $this->getResult($key)->available;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** retourner true si la valeur est valide */
|
/** retourner true si la valeur est valide */
|
||||||
function isValid($key=false): bool {
|
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 */
|
/** retourner true si la valeur est dans sa forme normalisée */
|
||||||
function isNormalized($key=false): bool {
|
function isNormalized($key=false): bool {
|
||||||
return $this->getResult()->normalized;
|
return $this->getResult($key)->normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,11 +85,11 @@ class AssocSchema extends Schema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWrapper(&$value=null, $valueKey=null, ?array $params=null, ?Wrapper &$wrapper=null): AssocWrapper {
|
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
|
# si pas de valeur ni de wrapper, pas d'analyse et donc pas d'exception
|
||||||
# cf le code similaire dans ScalarWrapper::__construct()
|
# cf le code similaire dans AssocWrapper::__construct()
|
||||||
$dontNormalize = $value === null && $wrapper === null;
|
$dontAnalyze = $value === null && $wrapper === null;
|
||||||
if (!($wrapper instanceof AssocWrapper)) $wrapper = $this->newWrapper();
|
if (!($wrapper instanceof AssocWrapper)) $wrapper = $this->newWrapper();
|
||||||
if ($params !== null) $wrapper->resetParams($params);
|
if ($params !== null) $wrapper->resetParams($params);
|
||||||
return $wrapper->reset($value, $valueKey, $dontNormalize? ["normalize" => false]: null);
|
return $wrapper->reset($value, $valueKey, $dontAnalyze? ["analyze" => false]: null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,9 +89,9 @@ class ScalarSchema extends Schema {
|
|||||||
function getWrapper(&$value=null, $valueKey=null, ?array $params=null, ?Wrapper &$wrapper=null): ScalarWrapper {
|
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
|
# si pas de valeur ni de wrapper, pas de vérification et donc pas d'exception
|
||||||
# cf le code similaire dans ScalarWrapper::__construct()
|
# 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 (!($wrapper instanceof ScalarWrapper)) $wrapper = $this->newWrapper();
|
||||||
if ($params !== null) $wrapper->resetParams($params);
|
if ($params !== null) $wrapper->resetParams($params);
|
||||||
return $wrapper->reset($value, $valueKey, $dontNormalize? ["normalize" => false]: null);
|
return $wrapper->reset($value, $valueKey, $dontAnalyze? ["analyze" => false]: null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,35 @@ class AssocSchemaTest extends TestCase {
|
|||||||
],
|
],
|
||||||
]), $schema->getDefinition());
|
]), $schema->getDefinition());
|
||||||
//yaml::dump($schema->getDefinition());
|
//yaml::dump($schema->getDefinition());
|
||||||
|
}
|
||||||
|
|
||||||
$wrapper = $schema->getWrapper();
|
function testWrapper() {
|
||||||
$wrapper->getKeys();
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user