[TASK] Object utility: Add option to specify allowed fields
This commit is contained in:
parent
33741a42f4
commit
f6b250d64b
@ -28,13 +28,20 @@ class ObjectUtility
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function fromArray(
|
public static function fromArray(
|
||||||
&$object, $data, $storageMapping = []
|
&$object, $data, $storageMapping = [], $allowedFields = []
|
||||||
) {
|
) {
|
||||||
$objectManager = GeneralUtility::makeInstance(
|
$objectManager = GeneralUtility::makeInstance(
|
||||||
ObjectManager::class
|
ObjectManager::class
|
||||||
);
|
);
|
||||||
$reflectionClass = new \ReflectionClass(get_class($object));
|
$reflectionClass = new \ReflectionClass(get_class($object));
|
||||||
foreach ($data as $property => $value) {
|
foreach ($data as $property => $value) {
|
||||||
|
if (
|
||||||
|
count($allowedFields)
|
||||||
|
&&
|
||||||
|
!in_array($property, $allowedFields)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$methodName = 'set' . ucfirst($property);
|
$methodName = 'set' . ucfirst($property);
|
||||||
if (!$reflectionClass->hasMethod($methodName)) {
|
if (!$reflectionClass->hasMethod($methodName)) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user