From f27e92544f675660d19ba6f5701d4698a1b3d3fd Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Mon, 16 Aug 2021 18:54:31 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8=20=D0=B2=D0=B8?= =?UTF-8?q?=D1=80=D1=82=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data2DtoConverter.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Data2DtoConverter.php b/src/Data2DtoConverter.php index c01ea39..d0aed54 100644 --- a/src/Data2DtoConverter.php +++ b/src/Data2DtoConverter.php @@ -18,6 +18,8 @@ class Data2DtoConverter { $tags = empty($tags) ? ['default'] : $tags; $reflectionObject = new \ReflectionObject($object); + + // Трнансформируем на уровне класса $this->processClassTransformers($reflectionObject, $data, $tags); if (is_object($data)) { return $data; @@ -33,9 +35,15 @@ class Data2DtoConverter // Для виртуальных полей добавляем пустой масиив, чтобы заполнить поля дто $propertyExtractor = new PropertyExtractor($property->class, $property->getName()); if ($propertyExtractor->fetch(VirtualProperty::class)) { - if (!array_key_exists($property->getName(), $data)) { - $data[$property->getName()] = []; + if ($property->isInitialized($object)) { + $propertyValue = $property->getValue($object); + $value = $this->convert($data, $propertyValue, $tags); + } else { + $value = $this->convert($data, new $propertyType, $tags); } + // присваиваем получившееся значение + $property->setValue($object, $value); + continue; } if ($dataPath = $this->grabDataPath($property, $data, $tags)) {