Настроил сохранение в приватные свойства

This commit is contained in:
Sipachev Igor 2021-08-17 16:43:49 +07:00
parent 5fa62d248e
commit 02f5719514

View File

@ -59,7 +59,7 @@ class Data2DtoConverter
continue;
}
$property->setValue($object, $value);
$this->setValue($object, $property, $value);
}
return $object;
@ -80,7 +80,7 @@ class Data2DtoConverter
$value = $this->convert($data, new $propertyType, $tags);
}
// присваиваем получившееся значение
$property->setValue($object, $value);
$this->setValue($object, $property, $value);
return true;
}
return false;
@ -92,7 +92,7 @@ class Data2DtoConverter
protected function processDataObject(object $object, \ReflectionProperty $property, $value): bool
{
if (is_object($value)) {
$property->setValue($object, $value);
$this->setValue($object, $property, $value);
return true;
}
return false;
@ -263,4 +263,17 @@ class Data2DtoConverter
}
return null;
}
private function setValue(object $object, \ReflectionProperty $property, $value)
{
if (!$property->isPublic()) {
$property->setAccessible(true);
}
$property->setValue($object, $value);
if (!$property->isPublic()) {
$property->setAccessible(false);
}
}
}