schema = $schema; $this->reset($dest, $key, $verifix); } function isScalar(?ScalarValue &$scalar=null): bool { $scalar = $this; return true; } /** @var ScalarSchema schéma de cette valeur */ protected $schema; /** @var Input source et destination de la valeur */ protected $input; /** @var string|int clé de la valeur dans le tableau destination */ protected $key; /** @var ?Result résultat de l'analyse de la valeur */ protected $result; function reset(&$dest, $key=null, bool $verifix=true): Value { if ($dest instanceof Input) $input = $dest; else $input = new Input($dest); $this->input = $input; $this->key = $key; $this->result = null; #XXX résoudre les types ici? if ($verifix) $this->verifix(); return $this; } function exists(): bool { return $this->input->exists($this->key); } function get($default=null) { $key = $this->key; $input = $this->input; if ($input->exists($key)) return $input->get($key); else return $default; } function set($value): self { $this->input->set($value, $this->key); return $this; } /** @var IType */ protected $type; function getType(): IType { if ($this->type === null) $this->type = $this->schema->getType($this->key); return $this->type; } function valid(): bool { } function normalized(): bool { } /** * analyser, corriger éventuellement et normaliser la valeur * * si la valeur était déjà normalisée, retourner false. */ function verifix(bool $throw=true, ?Result &$result=null): bool { $type = $this->getType(); $key = $this->key; if ($key === null) $modified = $type->verifix($this->input, $throw, $result); else $modified = $type->verifix($this->input[$key], $throw, $result); $this->result = $result; return $modified; } function parse($value, bool $throw=true, ?Result &$result=null) { $this->getType()->verifix($value, $throw, $result); $this->set($value); $this->result = $result; return $value; } function format(?string $format=null): string { $type = $this->getType(); $key = $this->key; if ($key === null) return $type->format($this->input, $format); else return $type->format($this->input[$key], $format); } }