|
|
@ -42,27 +42,12 @@ class Dto2DataConverter |
|
|
|
|
|
|
|
|
|
|
|
$value = $this->grabValue($object, $sourceName); |
|
|
|
$value = $this->grabValue($object, $sourceName); |
|
|
|
|
|
|
|
|
|
|
|
if (is_object($value)) { |
|
|
|
// Если нет карты, то не сериализуем. |
|
|
|
// Если у объекта нет карты, то не сериализуем. |
|
|
|
if (is_object($value) && is_array($propertyInfo)) { |
|
|
|
if (!is_array($propertyInfo)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$value = $this->convertObjectByMap($value, $propertyInfo, $tags); |
|
|
|
$value = $this->convertObjectByMap($value, $propertyInfo, $tags); |
|
|
|
} elseif (is_iterable($value)) { |
|
|
|
} elseif (is_iterable($value)) { |
|
|
|
$tempValue = []; |
|
|
|
$map = is_array($propertyInfo) ? $propertyInfo : null; |
|
|
|
foreach ($value as $item) { |
|
|
|
$value = $this->convertArrayByMap($value, $map, $tags); |
|
|
|
if (is_scalar($item)) { |
|
|
|
|
|
|
|
$tempValue[] = $item; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (is_array($item)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (is_object($item)) { |
|
|
|
|
|
|
|
$tempValue[] = $this->convertObjectByMap($item, $propertyInfo, $tags); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$value = $tempValue; |
|
|
|
|
|
|
|
} elseif (!is_scalar($value) && null !== $value) { |
|
|
|
} elseif (!is_scalar($value) && null !== $value) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -77,6 +62,26 @@ class Dto2DataConverter |
|
|
|
return $data; |
|
|
|
return $data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function convertArrayByMap($data, ?array $map, array $tags = []): ?array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$tempValue = []; |
|
|
|
|
|
|
|
foreach ($data as $key => $item) { |
|
|
|
|
|
|
|
if (is_scalar($item)) { |
|
|
|
|
|
|
|
$tempValue[$key] = $item; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (is_iterable($item) && $map) { |
|
|
|
|
|
|
|
$tempValue[$key] = $this->convertArrayByMap($item, $map, $tags); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (is_object($item) && $map) { |
|
|
|
|
|
|
|
$tempValue[$key] = $this->convertObjectByMap($item, $map, $tags); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $tempValue ?: null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function grabValue(object $object, $sourceName) |
|
|
|
protected function grabValue(object $object, $sourceName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|