12 $this->initComplexProperties($data);
13 foreach ($data as $key => $value)
19 if (property_exists($this, $key))
40 public function toArray(
bool $filterEmptyValue =
false)
52 if (is_scalar($value))
57 if (is_array($value) || is_object($value))
60 foreach ($value as $index => $item)
62 if ($filterEmptyValue && $item ===
null)
70 $result[$index] = $this->
prepareValue($item, $filterEmptyValue);
90 private function initComplexProperties(array &$data)
93 foreach ($map as $key => $item)
95 if (!empty($item[
'isArray']) && !empty($data[$key]) && is_array($data[$key]))
98 foreach ($data[$key] as $property)
100 $this->$key[] = $this->prepareComplexProperty(
103 $item[
'isMandatory'] ??
false
107 elseif (empty($data[$key]))
113 $this->$key = $this->prepareComplexProperty(
116 $item[
'isMandatory'] ??
false
137 private function prepareComplexProperty(array $data, $className, $isMandatory =
false)
141 return new $className($data);
145 return new $className($data ?? []);