result = array_merge( array_fill_keys(static::KEYS, null), [ "resultAvailable" => false, "present" => false, "available" => false, "null" => false, "valid" => false, "normalized" => false, ]); } function __get(string $name) { return $this->result[$name]; } function __set(string $name, $value): void { $this->result[$name] = $value; } protected function getMessage(string $key, Schema $schema): string { $message = cl::get($schema->messages, $key); if ($message !== null) return $message; return cl::get(ref_schema::MESSAGES, $key); } function setMissing( Schema $schema): int { $this->resultAvailable = true; $this->present = false; $this->available = false; if (!$schema->required) { $this->null = false; $this->valid = true; $this->normalized = true; return ref_analyze::NORMALIZED; } else { $this->messageKey = $messageKey = "missing"; $this->message = $this->getMessage($messageKey, $schema); return ref_analyze::MISSING; } } function setUnavailable( Schema $schema): int { $this->resultAvailable = true; $this->present = true; $this->available = false; if (!$schema->required) { $this->null = false; $this->valid = true; $this->normalized = true; return ref_analyze::NORMALIZED; } else { $this->messageKey = $messageKey = "unavailable"; $this->message = $this->getMessage($messageKey, $schema); return ref_analyze::UNAVAILABLE; } } function setNull( Schema $schema): int { $this->resultAvailable = true; $this->present = true; $this->available = true; $this->null = true; if ($schema->nullable) { $this->valid = true; $this->normalized = true; return ref_analyze::NORMALIZED; } else { $this->messageKey = $messageKey = "null"; $this->message = $this->getMessage($messageKey, $schema); return ref_analyze::NULL; } } function setInvalid($value, Schema $schema, ?Throwable $exception=null): int { $this->resultAvailable = true; $this->present = true; $this->available = true; $this->null = false; $this->valid = false; $this->origValue = $value; $this->messageKey = $messageKey = "invalid"; $message = $this->getMessage($messageKey, $schema); if ($exception !== null) { $tmessage = ValueException::get_message($exception); if ($tmessage) $message = $tmessage; } $this->message = $message; $this->exception = $exception; return ref_analyze::INVALID; } function addInvalidMessage(Wrapper $wrapper): void { $this->resultAvailable = true; $this->present = true; $this->available = true; $this->null = false; $this->valid = false; $this->messageKey = "invalid"; $result = $wrapper->getResult(); $resultException = $result->exception; $resultMessage = $result->message; if ($resultException !== null) { $tmessage = ValueException::get_message($resultException); if ($tmessage) { if ($resultMessage !== null) $resultMessage .= ": "; $resultMessage .= $tmessage; } } $message = $this->message; if ($message) $message .= "\n"; $message .= $resultMessage; $this->message = $message; } function setValid($normalizedValue=null): int { $this->resultAvailable = true; $this->present = true; $this->available = true; $this->null = false; $this->valid = true; $this->normalizedValue = $normalizedValue; return ref_analyze::VALID; } function setNormalized(): int { $this->resultAvailable = true; $this->present = true; $this->available = true; $this->null = false; $this->valid = true; $this->normalized = true; return ref_analyze::NORMALIZED; } function throw(bool $throw): void { if ($throw) { $exception = $this->exception; if ($exception !== null) throw $exception; else throw new ValueException($this->message); } } }