diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 03d9549..04f133a 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -2,5 +2,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
index 6a1b2d2..9891bef 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -10,6 +10,11 @@
+
+
+
+
+
@@ -64,6 +69,11 @@
+
+
+
+
+
@@ -72,6 +82,11 @@
+
+
+
+
+
diff --git a/src/schema/AnalyzerContext.php b/src/schema/AnalyzerContext.php
index 3e540c9..eb35003 100644
--- a/src/schema/AnalyzerContext.php
+++ b/src/schema/AnalyzerContext.php
@@ -11,6 +11,7 @@ class AnalyzerContext {
$this->destKey = $destKey;
$this->result = $result;
$this->type = null;
+ $this->orig = null;
$this->value = null;
}
@@ -21,5 +22,7 @@ class AnalyzerContext {
public Result $result;
public ?IType $type;
/** @var mixed */
+ public $orig;
+ /** @var mixed */
public $value;
}
diff --git a/src/schema/_scalar/ScalarValue.php b/src/schema/_scalar/ScalarValue.php
index b4d6269..b96316d 100644
--- a/src/schema/_scalar/ScalarValue.php
+++ b/src/schema/_scalar/ScalarValue.php
@@ -6,8 +6,6 @@ use nulib\ref\schema\ref_analyze;
use nulib\ValueException;
use nur\sery\wip\schema\AnalyzerContext;
use nur\sery\wip\schema\input\Input;
-use nur\sery\wip\schema\Result;
-use nur\sery\wip\schema\Schema;
use nur\sery\wip\schema\types;
use nur\sery\wip\schema\types\IType;
use nur\sery\wip\schema\Value;
@@ -57,8 +55,7 @@ class ScalarValue extends Value {
$this->destKey = $destKey;
$this->type = null;
$this->analyzeExtractParse();
- if ($verifix === null) $verifix = $this->defaultVerifix;
- if ($verifix) $this->verifix();
+ if ($verifix ?? $this->defaultVerifix) $this->verifix();
return $this;
}
@@ -123,32 +120,37 @@ class ScalarValue extends Value {
# sinon prendre le premier type
if (!$haveType) $type = $this->type = $firstType;
+ $context->type = $type;
if (!$type->isAvailable($input, $destKey)) return $result->setUnavailable($schema);
- $value = $context->value = $input->get($destKey);
- if ($type->isNull($value)) return $result->setNull($schema);
- if ($type->isValid($value, $normalized)) {
+ $value = $input->get($destKey);
+ $context->orig = $context->value = $value;
+ if ($type->isNull($value)) {
+ return $result->setNull($schema);
+ } elseif (is_string($value)) {
+ return ref_analyze::STRING;
+ } elseif ($type->isValid($value, $normalized)) {
if ($normalized) return $result->setNormalized();
else return $result->setValid();
+ } else {
+ return $result->setInvalid($value, $schema);
}
-
- if (is_string($value)) return ref_analyze::STRING;
- else return $result->setInvalid($value, $schema);
}
- function _extract(AnalyzerContext $context): void {
- $value = $context->value;
- $value = $context->type->extract($value);
- $context->value = $value;
+ function _extract(AnalyzerContext $context): bool {
+ return $context->type->extract($context->value);
}
- function _parse(AnalyzerContext $context): void {
- $value = $context->value;
- $value = $context->type->parse($value);
- $context->value = $value;
+ function _parse(AnalyzerContext $context): bool {
+ try {
+ $context->value = $context->type->parse($context->value);
+ return true;
+ } catch (ValueException $e) {
+ return false;
+ }
}
- function analyzeExtractParse(): void {
+ function analyzeExtractParse(): int {
$schema = $this->schema;
$input = $this->input;
$destKey = $this->destKey;
@@ -160,18 +162,31 @@ class ScalarValue extends Value {
$analyzerFunc = $schema->analyzerFunc;
if ($analyzerFunc !== null) $what = $analyzerFunc->invoke([$context]);
else $what = $this->_analyze($context);
+ if ($what !== ref_analyze::STRING) return $what;
- if ($what === ref_analyze::STRING) {
- /** @var func $extractorFunc */
- $extractorFunc = $schema->extractorFunc;
- if ($extractorFunc !== null) $extractorFunc->invoke([$context]);
- else $this->_extract($context);
+ /** @var func $extractorFunc */
+ $extractorFunc = $schema->extractorFunc;
+ if ($extractorFunc !== null) $valid = $extractorFunc->invoke([$context]);
+ else $valid = $this->_extract($context);
+ if (!$valid) return $result->setInvalid($context->orig, $schema);
+ if ($context->type->isNull($context->value)) return $result->setNull($schema);
+ $extracted = $context->value;
- /** @var func $parserFunc */
- $parserFunc = $schema->parserFunc;
- if ($parserFunc !== null) $parserFunc->invoke([$context]);
- else $this->_parse($context);
+ /** @var func $parserFunc */
+ $parserFunc = $schema->parserFunc;
+ if ($parserFunc !== null) $valid = $parserFunc->invoke([$context]);
+ else $valid = $this->_parse($context);
+ if ($valid) {
+ $normalized = $context->value === $context->orig;
+ if ($normalized) {
+ $input->set($context->value, $destKey);
+ return $result->setNormalized();
+ } else {
+ $input->set($extracted, $destKey);
+ return $result->setValid();
+ }
}
+ return $result->setInvalid($context->orig, $schema);
}
function verifix(?bool $throw=null): bool {
@@ -247,6 +262,18 @@ class ScalarValue extends Value {
}
function format($format=null): string {
- return $this->type->format($this->input->get($this->destKey), $format);
+ $value = $this->input->get($this->destKey);
+ /** @var func $formatterFunc */
+ $formatterFunc = $this->schema->formatterFunc;
+ if ($formatterFunc !== null) {
+ # la fonction formatter n'a pas forcément accès au format de la définition
+ # le lui fournir ici
+ $format ??= $this->schema->format;
+ return $formatterFunc->invoke([$value, $format]);
+ } else {
+ # on assume que le type a été initialisé avec le format de la définition
+ # le cas échéant
+ return $this->type->format($value, $format);
+ }
}
}
diff --git a/src/schema/types.php b/src/schema/types.php
index 4c5c8f2..96b703d 100644
--- a/src/schema/types.php
+++ b/src/schema/types.php
@@ -9,6 +9,7 @@ use nur\sery\wip\schema\types\tcallable;
use nur\sery\wip\schema\types\tfloat;
use nur\sery\wip\schema\types\tint;
use nur\sery\wip\schema\types\trawstring;
+use nur\sery\wip\schema\types\ttext;
/**
* Class types: classe outil pour gérer le registre de types
@@ -30,6 +31,7 @@ class types {
static function rawstring(): trawstring { return self::get("rawstring"); }
static function string(): tstring { return self::get("string"); }
+ static function text(): ttext { return self::get("text"); }
static function bool(): tbool { return self::get("bool"); }
static function int(): tint { return self::get("int"); }
static function float(): tfloat { return self::get("float"); }
diff --git a/src/schema/types/IType.php b/src/schema/types/IType.php
index 30969e1..5fcbda4 100644
--- a/src/schema/types/IType.php
+++ b/src/schema/types/IType.php
@@ -1,6 +1,7 @@
trawstring::class,
"string" => tstring::class,
+ "text" => ttext::class,
"bool" => tbool::class, "boolean" => tbool::class,
"int" => tint::class, "integer" => tint::class,
"float" => tfloat::class, "flt" => tfloat::class,
@@ -29,7 +30,7 @@ class Registry {
function get(string $name, ?array $params=null, ?array $definition=null): IType {
$class = self::TYPES[$name];
- $params = cl::merge($class::get_params($definition), $params);
+ $params = cl::merge($class::get_params_from_definition($definition), $params);
if ($params !== null) {
return func::with([$class, false, $params])->invoke();
}
diff --git a/src/schema/types/_tformatable.php b/src/schema/types/_tformatable.php
new file mode 100644
index 0000000..b2bf084
--- /dev/null
+++ b/src/schema/types/_tformatable.php
@@ -0,0 +1,19 @@
+params["format"] ?? static::FORMAT;
+ if ($format !== null) return sprintf($format, $value);
+ else return strval($value);
+ }
+}
diff --git a/src/schema/types/_tsimple.php b/src/schema/types/_tsimple.php
index b858461..c6d213c 100644
--- a/src/schema/types/_tsimple.php
+++ b/src/schema/types/_tsimple.php
@@ -4,7 +4,7 @@ namespace nur\sery\wip\schema\types;
use nur\sery\wip\schema\input\Input;
abstract class _tsimple implements IType {
- static function get_params(?array $definition): ?array {
+ static function get_params_from_definition(?array $definition): ?array {
return null;
}
@@ -19,14 +19,10 @@ abstract class _tsimple implements IType {
}
function isNull($value): bool {
- return $value === null || (is_string($value) && trim($value) === "");
+ return $value === null || $value === "";
}
- function extract(string $value): string {
- return $value;
- }
-
- function parse(string $value) {
- return $value;
+ function extract(string &$value): bool {
+ return true;
}
}
diff --git a/src/schema/types/_tstring.php b/src/schema/types/_tstring.php
new file mode 100644
index 0000000..d4928ff
--- /dev/null
+++ b/src/schema/types/_tstring.php
@@ -0,0 +1,26 @@
+params["trim"] ?? static::TRIM) $value = trim($value);
+ if ($this->params["norm_nl"] ?? static::NORM_NL) $value = str::norm_nl($value);
+ return true;
+ }
+}
diff --git a/src/schema/types/tarray.php b/src/schema/types/tarray.php
index c03d5fe..a668595 100644
--- a/src/schema/types/tarray.php
+++ b/src/schema/types/tarray.php
@@ -2,10 +2,24 @@
namespace nur\sery\wip\schema\types;
use nulib\cl;
+use nur\sery\wip\schema\_scalar\ScalarResult;
+use nur\sery\wip\schema\_scalar\ScalarSchema;
use nur\sery\wip\schema\Result;
use nur\sery\wip\schema\Schema;
-class tarray extends _tsimple {
+class tarray extends _tstring {
+ const SPLIT_PATTERN = '/\s+/';
+ const FORMAT = " ";
+
+ public static function get_params_from_definition(?array $definition): ?array {
+ $params = parent::get_params_from_definition($definition);
+ $splitPattern = $definition["split_pattern"] ?? null;
+ if ($splitPattern !== null) $params["split_pattern"] = $splitPattern;
+ $format = $definition["format"] ?? null;
+ if ($format !== null) $params["format"] = $format;
+ return $params;
+ }
+
static function ensure_array(&$array): void {
if (!is_array($array)) $array = cl::with($array);
}
@@ -19,9 +33,32 @@ class tarray extends _tsimple {
return is_scalar($value) || is_array($value);
}
- function verifix(&$value, Result &$result, Schema $schema): bool {
+ function parse(string $value) {
+ $pattern = $this->params["split_pattern"] ?? static::SPLIT_PATTERN;
+ return preg_split($pattern, $value);
+ }
+
+ /**
+ * @var ScalarResult $result
+ * @var ScalarSchema $schema
+ */
+ function verifix(&$value, Result $result, Schema $schema): bool {
+ if (is_array($value)) {
+ $result->setNormalized();
+ return false;
+ } elseif (is_scalar($value)) {
+ $value = cl::with($value);
+ $result->setValid();
+ return true;
+ } else {
+ $result->setInvalid($value, $schema);
+ return false;
+ }
}
function format($value, $format=null): string {
+ if ($value === null) return "";
+ $format ??= $this->params["format"] ?? static::FORMAT;
+ return implode($format, $value);
}
}
diff --git a/src/schema/types/tbool.php b/src/schema/types/tbool.php
index 2f5e426..8fb762c 100644
--- a/src/schema/types/tbool.php
+++ b/src/schema/types/tbool.php
@@ -9,17 +9,15 @@ use nur\sery\wip\schema\input\Input;
use nur\sery\wip\schema\Result;
use nur\sery\wip\schema\Schema;
-class tbool extends _tsimple {
+class tbool extends _tformatable {
/** liste de valeurs chaines à considérer comme 'OUI' */
const YES_VALUES = [
- # IMPORTANT: ordonner par taille décroissante pour compatibilité avec parse()
"true", "vrai", "yes", "oui",
"t", "v", "y", "o", "1",
];
/** liste de valeurs chaines à considérer comme 'NON' */
const NO_VALUES = [
- # IMPORTANT: ordonner par taille décroissante pour compatibilité avec parse()
"false", "faux", "non", "no",
"f", "n", "0",
];
@@ -59,35 +57,36 @@ class tbool extends _tsimple {
function isValid($value, ?bool &$normalized=null): bool {
$normalized = is_bool($value);
- if (is_string($value)) {
- $value = trim($value);
- $valid = self::is_yes($value) || self::is_no($value);
- } else {
- $valid = is_scalar($value);
- }
- return $valid;
+ return is_scalar($value);
+ }
+
+ function extract(string &$value): bool {
+ $value = trim($value);
+ return true;
+ }
+
+ function parse(string $value) {
+ if (self::is_yes($value)) return true;
+ elseif (self::is_no($value)) return false;
+ throw new ValueException("une valeur booléenne est attendue");
}
/**
* @var ScalarResult $result
* @var ScalarSchema $schema
*/
- function verifix(&$value, Result &$result, Schema $schema): bool {
+ function verifix(&$value, Result $result, Schema $schema): bool {
if (is_bool($value)) {
$result->setNormalized();
return false;
- } elseif (is_string($value)) {
- $bool = trim($value);
- if (self::is_yes($bool)) $value = true;
- elseif (self::is_no($bool)) $value = false;
- else return $result->setInvalid($value, $schema);
} elseif (is_scalar($value)) {
$value = boolval($value);
+ $result->setValid();
+ return true;
} else {
- return $result->setInvalid($value, $schema);
+ $result->setInvalid($value, $schema);
+ return false;
}
- $result->setValid();
- return true;
}
const OUINON_FORMAT = ["Oui", "Non", false];
@@ -105,10 +104,10 @@ class tbool extends _tsimple {
"oz" => self::OZ_FORMAT,
];
- const DEFAULT_FORMAT = self::OUINON_FORMAT;
+ const FORMAT = self::OUINON_FORMAT;
function format($value, $format=null): string {
- if ($format === null) $format = static::DEFAULT_FORMAT;
+ $format ??= $this->params["format"] ?? static::FORMAT;
if (is_string($format)) {
$oformat = $format;
$format = cl::get(self::FORMATS, strtolower($oformat));
diff --git a/src/schema/types/tcallable.php b/src/schema/types/tcallable.php
index da70509..afdcadc 100644
--- a/src/schema/types/tcallable.php
+++ b/src/schema/types/tcallable.php
@@ -1,13 +1,17 @@
setNormalized();
+ return false;
+ } elseif (is_callable($value)) {
+ $value = func::with($value);
+ $result->setNormalized();
+ return true;
+ } else {
+ $result->setInvalid($value, $schema);
+ return false;
+ }
}
function format($value, $format=null): string {
diff --git a/src/schema/types/tcontent.php b/src/schema/types/tcontent.php
index 3ee3b79..0a950ca 100644
--- a/src/schema/types/tcontent.php
+++ b/src/schema/types/tcontent.php
@@ -1,6 +1,9 @@
setNormalized();
+ return false;
+ } elseif (is_scalar($value)) {
+ $value = strval($value);
+ $result->setValid();
+ return true;
+ } else {
+ $result->setInvalid($value, $schema);
+ return false;
+ }
}
function format($value, $format=null): string {
+ return c::to_string($value);
}
}
diff --git a/src/schema/types/tfloat.php b/src/schema/types/tfloat.php
index 4154f2a..b1ecee9 100644
--- a/src/schema/types/tfloat.php
+++ b/src/schema/types/tfloat.php
@@ -1,12 +1,13 @@
setNormalized();
return false;
- } elseif (is_string($value)) {
- $float = trim($value);
- if (is_numeric($float)) $value = floatval($float);
- else return $result->setInvalid($value, $schema);
} elseif (is_scalar($value)) {
$value = floatval($value);
+ $result->setValid();
+ return true;
} else {
- return $result->setInvalid($value, $schema);
+ $result->setInvalid($value, $schema);
+ return false;
}
- $result->setValid();
- return true;
- }
-
- function format($value, $format=null): string {
- if ($format !== null) return sprintf($format, $value);
- else return strval($value);
}
}
diff --git a/src/schema/types/tint.php b/src/schema/types/tint.php
index 1f3b9b6..5431a95 100644
--- a/src/schema/types/tint.php
+++ b/src/schema/types/tint.php
@@ -1,19 +1,13 @@
$format];
- }
-
+class tint extends _tformatable {
static function ensure_int(&$int): void {
if (!is_int($int)) $int = intval($int);
}
@@ -23,42 +17,38 @@ class tint extends _tsimple {
}
//const INT_PATTERN = '/^[-+]?[0-9]+(?:\.[0-9]*)?$/';
-
+
function isValid($value, ?bool &$normalized=null): bool {
$normalized = is_int($value);
- if (is_string($value)) {
- $value = str_replace(",", ".", trim($value));
- $valid = is_numeric($value);
- } else {
- $valid = is_scalar($value);
- }
- return $valid;
+ return is_scalar($value);
+ }
+
+ function extract(string &$value): bool {
+ $value = trim($value);
+ return true;
+ }
+
+ function parse(string $value) {
+ $value = str_replace(",", ".", trim($value));
+ if (is_numeric($value)) return intval($value);
+ throw new ValueException("une valeur numérique entière est attendue");
}
/**
* @var ScalarResult $result
* @var ScalarSchema $schema
*/
- function verifix(&$value, Result &$result, Schema $schema): bool {
+ function verifix(&$value, Result $result, Schema $schema): bool {
if (is_int($value)) {
$result->setNormalized();
return false;
- } elseif (is_string($value)) {
- $int = str_replace(",", ".", trim($value));
- if (is_numeric($int)) $value = intval($int);
- else return $result->setInvalid($value, $schema);
} elseif (is_scalar($value)) {
$value = intval($value);
+ $result->setValid();
+ return true;
} else {
- return $result->setInvalid($value, $schema);
+ $result->setInvalid($value, $schema);
+ return false;
}
- $result->setNormalized();
- return true;
- }
-
- function format($value, $format=null): string {
- $format ??= $this->params["format"] ?? null;
- if ($format !== null) return sprintf($format, $value);
- else return strval($value);
}
}
diff --git a/src/schema/types/tkey.php b/src/schema/types/tkey.php
index 63c3f04..ff10afb 100644
--- a/src/schema/types/tkey.php
+++ b/src/schema/types/tkey.php
@@ -1,12 +1,16 @@
setNormalized();
+ return false;
+ } elseif (is_scalar($value)) {
+ $value = strval($value);
+ $result->setValid();
+ return true;
+ } else {
+ $result->setInvalid($value, $schema);
+ return false;
+ }
}
function format($value, $format=null): string {
+ return strval($value);
}
}
diff --git a/src/schema/types/tpkey.php b/src/schema/types/tpkey.php
index 32e545c..3766b04 100644
--- a/src/schema/types/tpkey.php
+++ b/src/schema/types/tpkey.php
@@ -1,17 +1,20 @@
setNormalized();
+ return false;
+ } elseif (is_scalar($value)) {
+ $value = strval($value);
+ $result->setValid();
+ return true;
+ } else {
+ $result->setInvalid($value, $schema);
+ return false;
+ }
}
function format($value, $format=null): string {
+ if (is_array($value)) return implode(".", $value);
+ else return strval($value);
}
}
diff --git a/src/schema/types/trawstring.php b/src/schema/types/trawstring.php
index 2ac0610..f36bdd1 100644
--- a/src/schema/types/trawstring.php
+++ b/src/schema/types/trawstring.php
@@ -1,71 +1,50 @@
trim = boolval($this->params["trim"] ?? static::TRIM);
- }
-
- protected bool $trim;
-
function isNull($value): bool {
return $value === null;
}
- protected function check_normalized(string $value, bool $trim): bool {
- if ($trim && $value !== "") {
- if (preg_match('/^\s+/', $value)) {
- return false;
- } elseif (preg_match('/\s+$/', $value)) {
- return false;
- }
- }
- return true;
- }
-
function isValid($value, ?bool &$normalized=null): bool {
if (is_string($value)) {
- $normalized = self::check_normalized($value, $this->trim);
+ $normalized = true;
return true;
}
return is_scalar($value);
}
-
+
+ function parse(string $value) {
+ return $value;
+ }
+
/**
* @var ScalarResult $result
* @var ScalarSchema $schema
*/
- function verifix(&$value, Result &$result, Schema $schema): bool {
+ function verifix(&$value, Result $result, Schema $schema): bool {
if (is_string($value)) {
- $normalized = false;
- if ($this->trim) {
- $orig = $value;
- $value = trim($value);
- $normalized = $value !== $orig;
- }
$result->setNormalized();
- return $normalized;
+ return false;
} elseif (is_scalar($value)) {
$value = strval($value);
- if ($this->trim) $value = trim($value);
- $result->setNormalized();
+ $result->setValid();
return true;
} else {
$result->setInvalid($value, $schema);
diff --git a/src/schema/types/ttext.php b/src/schema/types/ttext.php
new file mode 100644
index 0000000..e6271c4
--- /dev/null
+++ b/src/schema/types/ttext.php
@@ -0,0 +1,7 @@
+newValue();
- $string = null;
- $value->reset($string, null, false);
+ $string = null; $value->reset($string, null, false);
$this->checkValue($value, null, true, true, false, false);
self::assertException(ValueException::class, function() use (&$value) {
- $string = null;
- $value->reset($string);
+ $string = null; $value->reset($string);
});
$string = ""; $value->reset($string, null, false);
@@ -53,12 +52,12 @@ class ScalarValueTest extends TestCase {
$string = true; $value->reset($string, null, false);
$this->checkValue($value, true, true, true, true, false);
$string = true; $value->reset($string);
- $this->checkValue($value, "1", true, true, true, true);
+ $this->checkValue($value, "1", true, true, true, false);
$string = 42; $value->reset($string, null, false);
$this->checkValue($value, 42, true, true, true, false);
$string = 42; $value->reset($string);
- $this->checkValue($value, "42", true, true, true, true);
+ $this->checkValue($value, "42", true, true, true, false);
$string = []; $value->reset($string, null, false);
$this->checkValue($value, [], true, true, false, false);
@@ -85,6 +84,42 @@ class ScalarValueTest extends TestCase {
self::assertException(ValueException::class, function() use (&$value) {
$string = false; $value->reset($string);
});
+
+ ## Tester allow_empty === false
+ $schema = new ScalarSchema("rawstring");
+ $value = $schema->newValue();
+
+ $string = null; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input, null, false);
+ $this->checkValue($value, null, true, true, false, false);
+ self::assertException(ValueException::class, function() use (&$value) {
+ $string = null; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input);
+ });
+
+ $string = ""; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input, null, false);
+ $this->checkValue($value, null, true, false, true, true);
+ $string = ""; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input);
+ $this->checkValue($value, null, true, false, true, true);
+
+ $schema = new ScalarSchema("?rawstring");
+ $value = $schema->newValue();
+
+ $string = null; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input, null, false);
+ $this->checkValue($value, null, true, true, true, true);
+ $string = null; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input);
+ $this->checkValue($value, null, true, true, true, true);
+
+ $string = ""; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input, null, false);
+ $this->checkValue($value, null, true, false, true, true);
+ $string = ""; $input = new Input($string, ["allow_empty" => false]);
+ $value->reset($input);
+ $this->checkValue($value, null, true, false, true, true);
}
function testString() {
@@ -104,7 +139,7 @@ class ScalarValueTest extends TestCase {
$this->checkValue($value, "", true, true, true, true);
$string = " "; $value->reset($string, null, false);
- $this->checkValue($value, " ", true, true, true, false);
+ $this->checkValue($value, "", true, true, true, false);
$string = " "; $value->reset($string);
$this->checkValue($value, "", true, true, true, true);
@@ -114,7 +149,7 @@ class ScalarValueTest extends TestCase {
$this->checkValue($value, "text", true, true, true, true);
$string = " text "; $value->reset($string, null, false);
- $this->checkValue($value, " text ", true, true, true, false);
+ $this->checkValue($value, "text", true, true, true, false);
$string = " text "; $value->reset($string);
$this->checkValue($value, "text", true, true, true, true);
@@ -126,12 +161,12 @@ class ScalarValueTest extends TestCase {
$string = true; $value->reset($string, null, false);
$this->checkValue($value, true, true, true, true, false);
$string = true; $value->reset($string);
- $this->checkValue($value, "1", true, true, true, true);
+ $this->checkValue($value, "1", true, true, true, false);
$string = 42; $value->reset($string, null, false);
$this->checkValue($value, 42, true, true, true, false);
$string = 42; $value->reset($string);
- $this->checkValue($value, "42", true, true, true, true);
+ $this->checkValue($value, "42", true, true, true, false);
$string = []; $value->reset($string, null, false);
$this->checkValue($value, [], true, true, false, false);
@@ -179,17 +214,22 @@ class ScalarValueTest extends TestCase {
$int = "42"; $value->reset($int, null, false);
$this->checkValue($value, "42", true, true, true, false);
$int = "42"; $value->reset($int);
- $this->checkValue($value, 42, true, true, true, true);
+ $this->checkValue($value, 42, true, true, true, false);
$int = "42.5"; $value->reset($int, null, false);
$this->checkValue($value, "42.5", true, true, true, false);
$int = "42.5"; $value->reset($int);
- $this->checkValue($value, 42, true, true, true, true);
+ $this->checkValue($value, 42, true, true, true, false);
$int = "42,5"; $value->reset($int, null, false);
$this->checkValue($value, "42,5", true, true, true, false);
$int = "42,5"; $value->reset($int);
- $this->checkValue($value, 42, true, true, true, true);
+ $this->checkValue($value, 42, true, true, true, false);
+
+ $int = " 42 "; $value->reset($int, null, false);
+ $this->checkValue($value, "42", true, true, true, false);
+ $int = " 42 "; $value->reset($int);
+ $this->checkValue($value, 42, true, true, true, false);
$int = ""; $value->reset($int, null, false);
$this->checkValue($value, "", true, true, false, false);
@@ -206,7 +246,7 @@ class ScalarValueTest extends TestCase {
});
$int = "text"; $value->reset($int, null, false);
- $this->checkValue($value, "text", true, true, false, true);
+ $this->checkValue($value, "text", true, true, false, false);
self::assertException(ValueException::class, function() use (&$value) {
$int = "text";
$value->reset($int);
@@ -220,7 +260,7 @@ class ScalarValueTest extends TestCase {
$int = true; $value->reset($int, null, false);
$this->checkValue($value, true, true, true, true, false);
$int = true; $value->reset($int);
- $this->checkValue($value, 1, true, true, true, true);
+ $this->checkValue($value, 1, true, true, true, false);
$int = []; $value->reset($int, null, false);
$this->checkValue($value, [], true, true, false, false);