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 $destKey; /** @var ?Result résultat de l'analyse de la valeur */ protected $result; function reset(&$dest, $destKey=null, bool $verifix=true): Value { if ($dest instanceof Input) $input = $dest; else $input = new Input($dest); $this->input = $input; $this->destKey = $destKey; $this->result = null; #XXX résoudre les types ici? if ($verifix) $this->verifix(); return $this; } function exists(): bool { return $this->input->exists($this->destKey); } function get($default=null) { $destKey = $this->destKey; $input = $this->input; if ($input->exists($destKey)) return $input->get($destKey); else return $default; } function set($value): self { $this->input->set($value, $this->destKey); return $this; } /** @var IType */ protected $type; function getType(): IType { if ($this->type === null) $this->type = $this->schema->getType($this->destKey); 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->destKey; 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->destKey; if ($key === null) return $type->format($this->input, $format); else return $type->format($this->input[$key], $format); } }