|
|
@ -36,16 +36,12 @@ class Dto2DataConverter |
|
|
|
foreach ($map as $key => $propertyInfo) { |
|
|
|
foreach ($map as $key => $propertyInfo) { |
|
|
|
$sourceName = is_array($propertyInfo) ? $key : $propertyInfo; |
|
|
|
$sourceName = is_array($propertyInfo) ? $key : $propertyInfo; |
|
|
|
|
|
|
|
|
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|
if (!method_exists($object, $sourceName) && !property_exists($object, $sourceName)) { |
|
|
|
$reflectionSource = new ReflectionMethod($object, $sourceName); |
|
|
|
|
|
|
|
$value = $this->getMethodValue($object, $reflectionSource); |
|
|
|
|
|
|
|
} elseif (property_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionProperty($object, $sourceName); |
|
|
|
|
|
|
|
$value = $this->getValue($object, $reflectionSource); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$value = $this->grabValue($object, $sourceName); |
|
|
|
|
|
|
|
|
|
|
|
if (is_object($value)) { |
|
|
|
if (is_object($value)) { |
|
|
|
// Если у объекта нет карты, то не сериализуем. |
|
|
|
// Если у объекта нет карты, то не сериализуем. |
|
|
|
if (!is_array($propertyInfo)) { |
|
|
|
if (!is_array($propertyInfo)) { |
|
|
@ -67,19 +63,12 @@ class Dto2DataConverter |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$value = $tempValue; |
|
|
|
$value = $tempValue; |
|
|
|
} elseif (!is_scalar($value)) { |
|
|
|
} elseif (!is_scalar($value) && null !== $value) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|
$this->processIterationTransformers($object, $sourceName, $value, $tags); |
|
|
|
$this->processMethodTransformers($reflectionSource, $value, $tags); |
|
|
|
$dataPath = $this->grabIterationDataPath($object, $sourceName, $tags); |
|
|
|
$dataPath = $this->grabMethodDataPath($reflectionSource, $tags); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$this->processTransformers($reflectionSource, $value, $tags); |
|
|
|
|
|
|
|
$dataPath = $this->grabDataPath($reflectionSource, $tags); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dataPath = $dataPath ?? $sourceName; |
|
|
|
|
|
|
|
$data[$dataPath] = $value; |
|
|
|
$data[$dataPath] = $value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -88,6 +77,42 @@ class Dto2DataConverter |
|
|
|
return $data; |
|
|
|
return $data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function grabValue(object $object, $sourceName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionMethod($object, $sourceName); |
|
|
|
|
|
|
|
return $this->getMethodValue($object, $reflectionSource); |
|
|
|
|
|
|
|
} elseif (property_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionProperty($object, $sourceName); |
|
|
|
|
|
|
|
return $this->getValue($object, $reflectionSource); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function processIterationTransformers(object $object, string $sourceName, &$value, array $tags): void |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionMethod($object, $sourceName); |
|
|
|
|
|
|
|
$this->processMethodTransformers($reflectionSource, $value, $tags); |
|
|
|
|
|
|
|
} elseif (property_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionProperty($object, $sourceName); |
|
|
|
|
|
|
|
$this->processTransformers($reflectionSource, $value, $tags); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function grabIterationDataPath(object $object, string $sourceName, array $tags): string |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (method_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionMethod($object, $sourceName); |
|
|
|
|
|
|
|
$dataPath = $this->grabMethodDataPath($reflectionSource, $tags); |
|
|
|
|
|
|
|
} elseif (property_exists($object, $sourceName)) { |
|
|
|
|
|
|
|
$reflectionSource = new ReflectionProperty($object, $sourceName); |
|
|
|
|
|
|
|
$dataPath = $this->grabDataPath($reflectionSource, $tags); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $dataPath ?? $sourceName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Получаем теги для обработки |
|
|
|
* Получаем теги для обработки |
|
|
|
*/ |
|
|
|
*/ |
|
|
|