modifs.mineures sans commentaires
This commit is contained in:
parent
753a6dc75d
commit
527d4c582b
|
@ -59,7 +59,7 @@ abstract class Value implements ArrayAccess, IteratorAggregate {
|
||||||
abstract function set($value): self;
|
abstract function set($value): self;
|
||||||
|
|
||||||
/** supprimer la valeur */
|
/** supprimer la valeur */
|
||||||
abstract function unset(): void;
|
abstract function unset(): self;
|
||||||
|
|
||||||
/** formatter la valeur pour affichage */
|
/** formatter la valeur pour affichage */
|
||||||
abstract function format($format=null): string;
|
abstract function format($format=null): string;
|
||||||
|
|
|
@ -10,9 +10,10 @@ use nur\sery\schema\types\IType;
|
||||||
use nur\sery\schema\Value;
|
use nur\sery\schema\Value;
|
||||||
|
|
||||||
class ScalarValue extends Value {
|
class ScalarValue extends Value {
|
||||||
function __construct(ScalarSchema $schema, &$dest=null, $destKey=null, bool $defaultVerifix=true) {
|
function __construct(ScalarSchema $schema, &$dest=null, $destKey=null, bool $defaultVerifix=true, bool $defaultThrow=true) {
|
||||||
$this->schema = $schema;
|
$this->schema = $schema;
|
||||||
$this->defaultVerifix = $defaultVerifix;
|
$this->defaultVerifix = $defaultVerifix;
|
||||||
|
$this->defaultThrow = $defaultThrow;
|
||||||
$this->result = new ScalarResult();
|
$this->result = new ScalarResult();
|
||||||
$this->reset($dest, $destKey);
|
$this->reset($dest, $destKey);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +32,9 @@ class ScalarValue extends Value {
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $defaultVerifix;
|
protected $defaultVerifix;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
protected $defaultThrow;
|
||||||
|
|
||||||
/** @var IType type de la valeur après analyse */
|
/** @var IType type de la valeur après analyse */
|
||||||
protected $type;
|
protected $type;
|
||||||
|
|
||||||
|
@ -44,7 +48,7 @@ class ScalarValue extends Value {
|
||||||
$this->destKey = $destKey;
|
$this->destKey = $destKey;
|
||||||
$this->type = null;
|
$this->type = null;
|
||||||
$this->_analyze();
|
$this->_analyze();
|
||||||
if ($verifix === null) $verifix = $this->defaultVerifix;
|
if ($verifix == null) $verifix = $this->defaultVerifix;
|
||||||
if ($verifix) $this->verifix();
|
if ($verifix) $this->verifix();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -89,16 +93,12 @@ class ScalarValue extends Value {
|
||||||
else return $result->setInvalid($schema);
|
else return $result->setInvalid($schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function verifix(?bool $throw=null): bool {
|
||||||
* analyser, corriger éventuellement et normaliser la valeur
|
|
||||||
*
|
|
||||||
* si la valeur était déjà normalisée, retourner false.
|
|
||||||
*/
|
|
||||||
function verifix(bool $throw=true): bool {
|
|
||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
$destKey = $this->destKey;
|
$destKey = $this->destKey;
|
||||||
$value = $this->input->get($destKey);
|
$value = $this->input->get($destKey);
|
||||||
$modified = $type->verifix($value, $this->result);
|
$modified = $type->verifix($value, $this->result);
|
||||||
|
if ($throw === null) $throw = $this->defaultThrow;
|
||||||
if ($this->result->valid) $this->input->set($value, $destKey);
|
if ($this->result->valid) $this->input->set($value, $destKey);
|
||||||
else $this->result->throw($throw);
|
else $this->result->throw($throw);
|
||||||
return $modified;
|
return $modified;
|
||||||
|
@ -141,11 +141,12 @@ class ScalarValue extends Value {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function unset(?bool $verifix=null): void {
|
function unset(?bool $verifix=null): Value {
|
||||||
$this->input->unset($this->destKey);
|
$this->input->unset($this->destKey);
|
||||||
$this->_analyze();
|
$this->_analyze();
|
||||||
if ($verifix === null) $verifix = $this->defaultVerifix;
|
if ($verifix === null) $verifix = $this->defaultVerifix;
|
||||||
if ($verifix) $this->verifix();
|
if ($verifix) $this->verifix();
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function format($format=null): string {
|
function format($format=null): string {
|
||||||
|
|
|
@ -8,15 +8,25 @@ use nur\sery\schema\Result;
|
||||||
* Interface IType: un type de données
|
* Interface IType: un type de données
|
||||||
*/
|
*/
|
||||||
interface IType {
|
interface IType {
|
||||||
function canAnalyze(Input $input, $desyKey): bool;
|
/** ce type peut-il analyser la donnée dans $input[$destKey] ? */
|
||||||
|
function canAnalyze(Input $input, $destKey): bool;
|
||||||
|
|
||||||
function isAvailable(Input $input, $desyKey): bool;
|
/** la donnée $input[$destKey] est-elle disponible? */
|
||||||
|
function isAvailable(Input $input, $destKey): bool;
|
||||||
|
|
||||||
|
/** la valeur $value est-elle nulle? */
|
||||||
function isNull($value): bool;
|
function isNull($value): bool;
|
||||||
|
|
||||||
|
/** la valeur $value est-elle valide et normalisée le cas échéant? */
|
||||||
function isValid($value, ?bool &$normalized=null): bool;
|
function isValid($value, ?bool &$normalized=null): bool;
|
||||||
|
|
||||||
function verifix(&$value, ?Result &$result): bool;
|
/**
|
||||||
|
* analyser, corriger éventuellement et normaliser la valeur
|
||||||
|
*
|
||||||
|
* si la valeur était déjà normalisée, retourner false.
|
||||||
|
*/
|
||||||
|
function verifix(&$value, Result &$result): bool;
|
||||||
|
|
||||||
function format($value, $format=null);
|
/** formatter la valeur pour affichage */
|
||||||
|
function format($value, $format=null): string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue