modifs.mineures sans commentaires
This commit is contained in:
parent
741a807420
commit
c2ec23be30
@ -98,13 +98,16 @@ interface IType {
|
||||
function parse(string $value);
|
||||
|
||||
/**
|
||||
* analyser, corriger éventuellement et normaliser la valeur
|
||||
*
|
||||
* NB: si $value est un string. elle doit avoir déjà été traitée au préalable
|
||||
* normaliser la valeur. elle *doit* déjà être valide.
|
||||
* Si $value est un string. elle *doit* avoir déjà été traitée au préalable
|
||||
* par extract() et parse()
|
||||
*
|
||||
* si la valeur était déjà normalisée, ou si une erreur s'est produite,
|
||||
* retourner false.
|
||||
* - si $result indique que la valeur est déjà normalisée, cette méthode ne
|
||||
* fait rien
|
||||
* - si la valeur était déjà normalisée, mettre à jour $result pour indiquer
|
||||
* que la valeur est normalisée et retourner false
|
||||
* - sinon, retourner true pour indiquer qu'il a fallut normaliser la valeur.
|
||||
* $result n'est pas modifié
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool;
|
||||
|
||||
|
@ -37,7 +37,7 @@ class tarray extends _tstring {
|
||||
|
||||
function isValid($value, ?bool &$normalized=null): bool {
|
||||
$normalized = is_array($value);
|
||||
return is_scalar($value) || is_array($value);
|
||||
return $normalized || is_scalar($value);
|
||||
}
|
||||
|
||||
function parse(string $value) {
|
||||
@ -50,22 +50,13 @@ class tarray extends _tstring {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_array($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_array($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_string($value)) {
|
||||
try {
|
||||
$value = $this->parse($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} catch (ValueException $e) {
|
||||
}
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = cl::with($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
}
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -100,22 +100,13 @@ class tbool extends _tformatable {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_bool($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_bool($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_string($value)) {
|
||||
try {
|
||||
$value = $this->parse($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} catch (ValueException $e) {
|
||||
}
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = boolval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
}
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class tcallable extends _tsimple {
|
||||
}
|
||||
|
||||
function isValid($value, ?bool &$normalized=null): bool {
|
||||
$normalized = is_callable($value);
|
||||
$normalized = $value instanceof func;
|
||||
return func::check($value);
|
||||
}
|
||||
|
||||
@ -44,22 +44,13 @@ class tcallable extends _tsimple {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if ($value instanceof func) {
|
||||
if ($result->normalized) {
|
||||
} elseif ($value instanceof func) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_callable($value)) {
|
||||
$value = func::with($value);
|
||||
$result->setNormalized();
|
||||
return true;
|
||||
} elseif (is_string($value)) {
|
||||
try {
|
||||
$value = $this->parse($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} catch (ValueException $e) {
|
||||
}
|
||||
}
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ abstract class tcontent extends _tunion {
|
||||
|
||||
function isValid($value, ?bool &$normalized=null): bool {
|
||||
$normalized = is_string($value) || is_array($value);
|
||||
return is_scalar($value) || is_array($value);
|
||||
return $normalized || is_scalar($value);
|
||||
}
|
||||
|
||||
function parse(string $value) {
|
||||
@ -37,17 +37,14 @@ abstract class tcontent extends _tunion {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_string($value) || is_array($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_string($value) || is_array($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = strval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} else {
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function format($value, $format=null): string {
|
||||
|
@ -44,22 +44,13 @@ class tfloat extends _tformatable {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_float($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_float($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_string($value)) {
|
||||
try {
|
||||
$value = $this->parse($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} catch (ValueException $e) {
|
||||
}
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = floatval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
}
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ class tgeneric extends _tsimple {
|
||||
}
|
||||
|
||||
function isValid($value, ?bool &$normalized=null): bool {
|
||||
$normalized = true;
|
||||
return $value instanceof $this->class;
|
||||
$normalized = $value instanceof $this->class;
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
function parse(string $value) {
|
||||
@ -42,7 +42,7 @@ class tgeneric extends _tsimple {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
$result->setNormalized();
|
||||
if (!$result->normalized) $result->setNormalized();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -46,22 +46,13 @@ class tint extends _tformatable {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_int($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_int($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_string($value)) {
|
||||
try {
|
||||
$value = $this->parse($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} catch (ValueException $e) {
|
||||
}
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = intval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
}
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class tkey extends _tunion {
|
||||
|
||||
function isValid($value, ?bool &$normalized=null): bool {
|
||||
$normalized = is_string($value) || is_int($value);
|
||||
return is_scalar($value);
|
||||
return $normalized || is_scalar($value);
|
||||
}
|
||||
|
||||
function parse(string $value) {
|
||||
@ -37,17 +37,14 @@ class tkey extends _tunion {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_string($value) || is_int($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_string($value) || is_int($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = strval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} else {
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function format($value, $format=null): string {
|
||||
|
@ -36,7 +36,7 @@ class tmixed extends _tsimple {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
$result->setNormalized();
|
||||
if (!$result->normalized) $result->setNormalized();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class tpkey extends _tunion {
|
||||
|
||||
function isValid($value, ?bool &$normalized=null): bool {
|
||||
$normalized = is_string($value) || is_int($value) || is_array($value);
|
||||
return is_scalar($value) || is_array($value);
|
||||
return $normalized || is_scalar($value);
|
||||
}
|
||||
|
||||
function parse(string $value) {
|
||||
@ -42,17 +42,14 @@ class tpkey extends _tunion {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_string($value) || is_int($value) || is_array($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_string($value) || is_int($value) || is_array($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = strval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} else {
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function format($value, $format=null): string {
|
||||
|
@ -45,17 +45,14 @@ class trawstring extends _tstring {
|
||||
* @var ScalarSchema $schema
|
||||
*/
|
||||
function normalize(&$value, Result $result, Schema $schema): bool {
|
||||
if (is_string($value)) {
|
||||
if ($result->normalized) {
|
||||
} elseif (is_string($value)) {
|
||||
$result->setNormalized();
|
||||
return false;
|
||||
} elseif (is_scalar($value)) {
|
||||
$value = strval($value);
|
||||
$result->setValid();
|
||||
return true;
|
||||
} else {
|
||||
$result->setInvalid($value, $schema);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function format($value, $format=null): string {
|
||||
|
Loading…
Reference in New Issue
Block a user