mvc - extend model implementation to support volatile fields, these fields will be validated when offered, but will not be serialized to the target xml structure.

Example usage:

<serial type="IntegerField" volatile="true"/>

The advantage of this is one can ask the user for input, validate it when offered and report back when it's not valid.
This commit is contained in:
Ad Schellevis 2024-02-26 16:21:03 +01:00
parent 8973f6efb1
commit c868e0adc6
2 changed files with 28 additions and 3 deletions

View File

@ -215,6 +215,9 @@ abstract class BaseModel
}
$fieldObject = $field_rfcls->newInstance($new_ref, $tagName);
$fieldObject->setParentModel($this);
if (($xmlNode->attributes()["volatile"] ?? '') == 'true') {
$fieldObject->setInternalIsVolatile();
}
// now add content to this model (recursive)
if ($fieldObject->isContainer() == false) {

View File

@ -1,7 +1,7 @@
<?php
/*
* Copyright (C) 2015-2020 Deciso B.V.
* Copyright (C) 2015-2024 Deciso B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -105,6 +105,11 @@ abstract class BaseField
*/
protected $internalIsVirtual = false;
/**
* @var bool node (and subnodes) is volatile (non persistent, but should validate when offered)
*/
protected $internalIsVolatile = false;
/**
* @var array key value store for attributes (will be saved as xml attributes)
*/
@ -573,6 +578,23 @@ abstract class BaseField
return $this->internalIsVirtual;
}
/**
* Mark this node as volatile
*/
public function setInternalIsVolatile()
{
$this->internalIsVolatile = true;
}
/**
* returns if this node is volatile, the framework uses this to determine if this node should be stored.
* @return bool is volatile node
*/
public function getInternalIsVolatile()
{
return $this->internalIsVolatile;
}
/**
* getter for internal tag name
* @return null|string xml tagname to use
@ -687,8 +709,8 @@ abstract class BaseField
}
foreach ($this->iterateItems() as $key => $FieldNode) {
if ($FieldNode->getInternalIsVirtual()) {
// Virtual fields should never be persisted
if ($FieldNode->getInternalIsVirtual() || $FieldNode->getInternalIsVolatile()) {
// Virtual and volatile fields should never be persisted
continue;
}
$FieldNode->addToXMLNode($subnode);