Убрал лишнюю рекурсию
This commit is contained in:
parent
ef336c0d2e
commit
a45c2907df
@ -28,6 +28,8 @@ class Data2DtoConverter
|
|||||||
$properties = $reflectionObject->getProperties();
|
$properties = $reflectionObject->getProperties();
|
||||||
/** @var \ReflectionProperty $property */
|
/** @var \ReflectionProperty $property */
|
||||||
foreach ($properties as $property) {
|
foreach ($properties as $property) {
|
||||||
|
// todo добавить атрибут на пропуск обработки и еще атрибут на допустимые поля
|
||||||
|
|
||||||
/** @var \ReflectionNamedType $reflectionPropertyType */
|
/** @var \ReflectionNamedType $reflectionPropertyType */
|
||||||
$reflectionPropertyType = $property->getType();
|
$reflectionPropertyType = $property->getType();
|
||||||
$propertyType = $reflectionPropertyType->getName();
|
$propertyType = $reflectionPropertyType->getName();
|
||||||
@ -53,7 +55,9 @@ class Data2DtoConverter
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->processClass($object, $property, $preparedPropertyType, $value, $tags);
|
if ($this->processClass($object, $property, $preparedPropertyType, $value, $tags)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->processNull($reflectionPropertyType, $value)) {
|
if ($this->processNull($reflectionPropertyType, $value)) {
|
||||||
continue;
|
continue;
|
||||||
@ -118,15 +122,20 @@ class Data2DtoConverter
|
|||||||
/**
|
/**
|
||||||
* Если это class, то рекурсивно заполняем дальше
|
* Если это class, то рекурсивно заполняем дальше
|
||||||
*/
|
*/
|
||||||
protected function processClass(object $object, ReflectionProperty $property, string $preparedPropertyType, &$value, array $tags)
|
protected function processClass(object $object, ReflectionProperty $property, string $preparedPropertyType, &$value, array $tags): bool
|
||||||
{
|
{
|
||||||
if (class_exists($preparedPropertyType)) {
|
if (class_exists($preparedPropertyType)) {
|
||||||
if ($property->isInitialized($object) && $propertyValue = $property->getValue($object)) {
|
$propertyValue = $property->getValue($object);
|
||||||
|
if (!is_array($propertyValue)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($property->isInitialized($object)) {
|
||||||
$value = $this->convert($value, $propertyValue, $tags);
|
$value = $this->convert($value, $propertyValue, $tags);
|
||||||
} else {
|
} else {
|
||||||
$value = $this->convert($value, new $preparedPropertyType, $tags);
|
$value = $this->convert($value, new $preparedPropertyType, $tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function grabValue(\ReflectionProperty $property, array $data, array $tags)
|
protected function grabValue(\ReflectionProperty $property, array $data, array $tags)
|
||||||
@ -244,6 +253,9 @@ class Data2DtoConverter
|
|||||||
}
|
}
|
||||||
$tempValue = [];
|
$tempValue = [];
|
||||||
foreach ($value as $itemValue) {
|
foreach ($value as $itemValue) {
|
||||||
|
if (!is_array($itemValue)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$tempValue[] = $this->convert($itemValue, new $attributedPropertyClass, $tags);
|
$tempValue[] = $this->convert($itemValue, new $attributedPropertyClass, $tags);
|
||||||
}
|
}
|
||||||
$value = $tempValue;
|
$value = $tempValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user