|
|
@@ -96,6 +96,13 @@ trait EntityTrait
|
|
|
protected $_errors = [];
|
|
|
|
|
|
/**
|
|
|
+ * List of invalid fields and their data for errors upon validation/patching
|
|
|
+ *
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $_invalid = [];
|
|
|
+
|
|
|
+ /**
|
|
|
* Map of properties in this entity that can be safely assigned, each
|
|
|
* property name points to a boolean indicating its status. An empty array
|
|
|
* means no properties are accessible
|
|
|
@@ -600,7 +607,7 @@ trait EntityTrait
|
|
|
}
|
|
|
|
|
|
$this->_dirty[$property] = true;
|
|
|
- unset($this->_errors[$property]);
|
|
|
+ unset($this->_errors[$property], $this->_invalid[$property]);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -615,6 +622,7 @@ trait EntityTrait
|
|
|
{
|
|
|
$this->_dirty = [];
|
|
|
$this->_errors = [];
|
|
|
+ $this->_invalid = [];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -780,6 +788,44 @@ trait EntityTrait
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Sets a field as invalid and not patchable into the entity.
|
|
|
+ *
|
|
|
+ * This is useful for batch operations when one needs to get the original value for an error message after patching.
|
|
|
+ * This value could not be patched into the entity and is simply copied into the _invalid property for debugging purposes
|
|
|
+ * or to be able to log it away.
|
|
|
+ *
|
|
|
+ * @param string|array|null $field The field to get invalid value for, or the value to set.
|
|
|
+ * @param mixed|null $value The invalid value to be set for $field.
|
|
|
+ * @param bool $overwrite Whether or not to overwrite pre-existing values for $field.
|
|
|
+ * @return $this|mixed
|
|
|
+ */
|
|
|
+ public function invalid($field = null, $value = null, $overwrite = false)
|
|
|
+ {
|
|
|
+ if ($field === null) {
|
|
|
+ return $this->_invalid;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_string($field) && $value === null) {
|
|
|
+ $value = isset($this->_invalid[$field]) ? $this->_invalid[$field] : null;
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!is_array($field)) {
|
|
|
+ $field = [$field => $value];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($field as $f => $value) {
|
|
|
+ if ($overwrite) {
|
|
|
+ $this->_invalid[$f] = $value;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $this->_invalid += [$f => $value];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Stores whether or not a property value can be changed or set in this entity.
|
|
|
* The special property `*` can also be marked as accessible or protected, meaning
|
|
|
* that any other property specified before will take its value. For example
|
|
|
@@ -881,6 +927,7 @@ trait EntityTrait
|
|
|
'[original]' => $this->_original,
|
|
|
'[virtual]' => $this->_virtual,
|
|
|
'[errors]' => $this->_errors,
|
|
|
+ '[invalid]' => $this->_invalid,
|
|
|
'[repository]' => $this->_registryAlias
|
|
|
];
|
|
|
}
|