[TASK] Object utility: Add option to specify allowed fields

This commit is contained in:
Philipp Dieter 2021-07-19 15:21:29 +02:00
parent 33741a42f4
commit f6b250d64b

View File

@ -28,13 +28,20 @@ class ObjectUtility
* @return void
*/
public static function fromArray(
&$object, $data, $storageMapping = []
&$object, $data, $storageMapping = [], $allowedFields = []
) {
$objectManager = GeneralUtility::makeInstance(
ObjectManager::class
);
$reflectionClass = new \ReflectionClass(get_class($object));
foreach ($data as $property => $value) {
if (
count($allowedFields)
&&
!in_array($property, $allowedFields)
) {
continue;
}
$methodName = 'set' . ucfirst($property);
if (!$reflectionClass->hasMethod($methodName)) {
continue;