modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-03-19 13:49:36 +04:00
parent 9328aac9e9
commit ef7e8551aa
2 changed files with 31 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace nur\sery\wip\schema\_assoc;
use nulib\ValueException;
use nur\sery\wip\schema\_scalar\ScalarResult;
use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\Result;
use nur\sery\wip\schema\types\IType;
@ -71,7 +72,23 @@ class AssocWrapper extends Wrapper {
* @param AssocWrapper $wrapper
*/
static function _analyze(?array $params, WrapperContext $context, Wrapper $wrapper): int {
return ScalarWrapper::_analyze($params, $context, $wrapper);
if ($context->ensureArray) {
$array = $context->input->get();
if ($array === null) $context->input->set([]);
}
$what = ScalarWrapper::_analyze($params, $context, $wrapper);
/** @var ScalarResult $result */
$result = $context->result;
if (!$result->valid) return $what;
foreach ($context->keyWrappers as $wrapper) {
$wrapper->analyze($params);
if (!$wrapper->isValid()) {
$result->setInvalid(null, $context->schema, $wrapper->getResult()->exception);
break;
#XXX
}
}
return $what;
}
static function _normalize(?array $params, WrapperContext $context, Wrapper $wrapper): bool {

View File

@ -2,10 +2,23 @@
namespace nur\sery\wip\schema\_assoc;
use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\input\Input;
use nur\sery\wip\schema\Schema;
use nur\sery\wip\schema\Wrapper;
use nur\sery\wip\schema\WrapperContext;
class AssocWrapperContext extends WrapperContext {
function __construct(Schema $schema, ?Input $input, $valueKey, ?array $params) {
parent::__construct($schema, $input, $valueKey, $params);
$this->ensureArray = $params["ensure_array"] ?? false;
$this->ensureKeys = $params["ensure_keys"] ?? true;
$this->ensureOrder = $params["ensure_order"] ?? true;
}
public bool $ensureArray;
public bool $ensureKeys;
public bool $ensureOrder;
public ?ScalarWrapper $arrayWrapper = null;
/** liste des clés valides */