Рефакторинг
Доп проверки
This commit is contained in:
parent
a45c2907df
commit
2a24a0eb49
@ -76,7 +76,8 @@ class Data2DtoConverter
|
|||||||
{
|
{
|
||||||
$propertyExtractor = new PropertyExtractor($property->class, $property->getName());
|
$propertyExtractor = new PropertyExtractor($property->class, $property->getName());
|
||||||
if ($propertyExtractor->fetch(VirtualProperty::class)) {
|
if ($propertyExtractor->fetch(VirtualProperty::class)) {
|
||||||
if ($property->isInitialized($object) && $propertyValue = $property->getValue($object)) {
|
$propertyValue = $this->getValue($object, $property);
|
||||||
|
if ($property->isInitialized($object) && $propertyValue) {
|
||||||
$value = $this->convert($data, $propertyValue, $tags);
|
$value = $this->convert($data, $propertyValue, $tags);
|
||||||
} else {
|
} else {
|
||||||
$propertyType = $property->getType()->getName();
|
$propertyType = $property->getType()->getName();
|
||||||
@ -125,11 +126,11 @@ class Data2DtoConverter
|
|||||||
protected function processClass(object $object, ReflectionProperty $property, string $preparedPropertyType, &$value, array $tags): bool
|
protected function processClass(object $object, ReflectionProperty $property, string $preparedPropertyType, &$value, array $tags): bool
|
||||||
{
|
{
|
||||||
if (class_exists($preparedPropertyType)) {
|
if (class_exists($preparedPropertyType)) {
|
||||||
$propertyValue = $property->getValue($object);
|
$propertyValue = $this->getValue($object, $property);
|
||||||
if (!is_array($propertyValue)) {
|
if (!is_array($value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($property->isInitialized($object)) {
|
if ($property->isInitialized($object) && $propertyValue) {
|
||||||
$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);
|
||||||
@ -286,4 +287,23 @@ class Data2DtoConverter
|
|||||||
$property->setAccessible(false);
|
$property->setAccessible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getValue(object $object, \ReflectionProperty $property)
|
||||||
|
{
|
||||||
|
if (!$property->isInitialized($object)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$property->isPublic()) {
|
||||||
|
$property->setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $property->getValue($object);
|
||||||
|
|
||||||
|
if (!$property->isPublic()) {
|
||||||
|
$property->setAccessible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user