7 private array $metaFields = [];
14 $this->initComplexProperties($data);
15 foreach ($data as $key => $value)
21 if (property_exists($this, $key))
33 public function toArray(
bool $filterEmptyValue =
false)
45 if (is_scalar($value))
50 if (is_array($value) || is_object($value))
53 foreach ($value as $index => $item)
55 if ($filterEmptyValue && $item ===
null)
63 $result[$index] = $this->
prepareValue($item, $filterEmptyValue);
73 private function initComplexProperties(array &$data)
76 foreach ($map as $key => $item)
78 if (!empty($item[
'isArray']) && !empty($data[$key]) && is_array($data[$key]))
81 foreach ($data[$key] as $property)
83 $this->$key[] = $this->prepareComplexProperty(
86 $item[
'isMandatory'] ??
false
90 elseif (empty($data[$key]))
96 $this->$key = $this->prepareComplexProperty(
99 $item[
'isMandatory'] ??
false
120 private function prepareComplexProperty(array $data, $className, $isMandatory =
false)
124 return new $className($data);
127 return new $className($data ?? []);
135 return $this->metaFields;
140 if (strpos($key,
'@') !==
false)
142 $this->metaFields[$key] = $value;
151 if (strpos($key,
'metaFields') !==
false)