modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2023-11-28 08:53:40 +04:00
parent 94790bef34
commit 0d91228f55
2 changed files with 12 additions and 7 deletions

View File

@ -51,7 +51,12 @@ class ScalarResult extends Result {
$this->result[$name] = $value;
}
function setMissing(ScalarSchema $schema, ?string $key=null): int {
protected static function replace_key(string &$message, ?string $key): void {
if ($key) $message = str_replace("{key}", $key, $message);
else $message = str_replace("{key}: ", "", $message);
}
function setMissing(ScalarSchema $schema): int {
$this->missing = true;
if (!$schema->required) {
$this->null = true;
@ -60,13 +65,13 @@ class ScalarResult extends Result {
return ref_analyze::NORMALIZED;
} else {
$message = cl::get($schema->messages, "missing");
$message = str_replace("{key}", $key, $message);
self::replace_key($message, $schema->name);
$this->message = $message;
return ref_analyze::MISSING;
}
}
function setNull(ScalarSchema $schema, ?string $key=null): int {
function setNull(ScalarSchema $schema): int {
$this->missing = true;
if ($schema->nullable) {
$this->valid = true;
@ -74,7 +79,7 @@ class ScalarResult extends Result {
return ref_analyze::NORMALIZED;
} else {
$message = cl::get($schema->messages, "null");
$message = str_replace("{key}", $key, $message);
self::replace_key($message, $schema->name);
$this->message = $message;
return ref_analyze::NULL;
}

View File

@ -60,10 +60,10 @@ class ScalarValue extends Value {
$destKey = $this->destKey;
$result = $this->result;
$result->reset();
if (!$input->available()) return $result->setMissing($schema, $destKey);
$value = $input->get($destKey);
if ($value === null) return $result->setNull($schema, $destKey);
#XXX résoudre le type
if (!$input->available()) return $result->setMissing($schema);
$value = $input->get($destKey);
if ($value === null) return $result->setNull($schema);
}
function exists(): bool {