|
|
@ -28,15 +28,22 @@ class Dto2DataConverter |
|
|
|
return $this->convertByMap($object, $schema->map, $tags); |
|
|
|
return $this->convertByMap($object, $schema->map, $tags); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function convertByMap($objectData, Map $map, array $tags = []): array |
|
|
|
public function convertByMap(object $object, array $map, array $tags = []): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$data = []; |
|
|
|
$data = []; |
|
|
|
|
|
|
|
|
|
|
|
$reflectionObject = new \ReflectionObject($object); |
|
|
|
$reflectionObject = new \ReflectionObject($object); |
|
|
|
foreach ($map->properties as $propertyName => $childMap) { |
|
|
|
foreach ($map as $propertyKey => $property) { |
|
|
|
|
|
|
|
if (is_array($property)) { |
|
|
|
|
|
|
|
$propertyName = $propertyKey; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$propertyName = $property; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$property = new ReflectionProperty($object, $propertyName); |
|
|
|
$property = new ReflectionProperty($object, $propertyName); |
|
|
|
$value = $this->getValue($object, $property); |
|
|
|
$value = $this->getValue($object, $property); |
|
|
|
if ($childMap && !is_scalar($value)) { |
|
|
|
$childMap = $property; |
|
|
|
|
|
|
|
if ($childMap && is_array($childMap) && !is_scalar($value)) { |
|
|
|
if (is_array($value)) { |
|
|
|
if (is_array($value)) { |
|
|
|
$tmpValue = []; |
|
|
|
$tmpValue = []; |
|
|
|
foreach ($value as $objectDataItem) { |
|
|
|
foreach ($value as $objectDataItem) { |
|
|
@ -53,23 +60,29 @@ class Dto2DataConverter |
|
|
|
$data[$dataPath] = $value; |
|
|
|
$data[$dataPath] = $value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach ($map->methods as $methodName => $childMap) { |
|
|
|
// foreach ($map->methods as $methodName => $childMap) { |
|
|
|
$method = new \ReflectionMethod($object, $methodName); |
|
|
|
// $method = new \ReflectionMethod($object, $methodName); |
|
|
|
$value = $this->getMethodValue($object, $method); |
|
|
|
// $value = $this->getMethodValue($object, $method); |
|
|
|
if ($childMap) { |
|
|
|
// if ($childMap) { |
|
|
|
$value = $this->convertByMap($value, $childMap, $tags); |
|
|
|
// $value = $this->convertByMap($value, $childMap, $tags); |
|
|
|
} |
|
|
|
// } |
|
|
|
$this->processMethodTransformers($method, $value, $tags); |
|
|
|
// $this->processMethodTransformers($method, $value, $tags); |
|
|
|
$dataPath = $this->grabMethodDataPath($method, $tags); |
|
|
|
// $dataPath = $this->grabMethodDataPath($method, $tags); |
|
|
|
$dataPath = $dataPath ?? $propertyName; |
|
|
|
// $dataPath = $dataPath ?? $propertyName; |
|
|
|
$data[$dataPath] = $value; |
|
|
|
// $data[$dataPath] = $value; |
|
|
|
} |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
$this->processClassTransformers($reflectionObject, $data, $tags); |
|
|
|
$this->processClassTransformers($reflectionObject, $data, $tags); |
|
|
|
|
|
|
|
|
|
|
|
return $data; |
|
|
|
return $data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function convertArrayByMap(array $data, array $map, array $tags = []): array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Получаем теги для обработки |
|
|
|
* Получаем теги для обработки |
|
|
|
*/ |
|
|
|
*/ |
|
|
|