|
|
@ -7,7 +7,7 @@ use Rinsvent\AttributeExtractor\ClassExtractor; |
|
|
|
use Rinsvent\AttributeExtractor\PropertyExtractor; |
|
|
|
use Rinsvent\AttributeExtractor\PropertyExtractor; |
|
|
|
use Rinsvent\Data2DTO\Attribute\DTOMeta; |
|
|
|
use Rinsvent\Data2DTO\Attribute\DTOMeta; |
|
|
|
use Rinsvent\Data2DTO\Attribute\PropertyPath; |
|
|
|
use Rinsvent\Data2DTO\Attribute\PropertyPath; |
|
|
|
use Rinsvent\Data2DTO\Attribute\TagsResolver; |
|
|
|
use Rinsvent\Data2DTO\Attribute\HandleTags; |
|
|
|
use Rinsvent\Data2DTO\Attribute\VirtualProperty; |
|
|
|
use Rinsvent\Data2DTO\Attribute\VirtualProperty; |
|
|
|
use Rinsvent\Data2DTO\Resolver\TransformerResolverStorage; |
|
|
|
use Rinsvent\Data2DTO\Resolver\TransformerResolverStorage; |
|
|
|
use Rinsvent\Data2DTO\Transformer\Meta; |
|
|
|
use Rinsvent\Data2DTO\Transformer\Meta; |
|
|
@ -16,13 +16,16 @@ use function Symfony\Component\String\u; |
|
|
|
|
|
|
|
|
|
|
|
class Data2DtoConverter |
|
|
|
class Data2DtoConverter |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
public function getTags(array $data, object $object, array $tags = []): array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->processTags($object, $data, $tags); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function convert(array $data, object $object, array $tags = []): object |
|
|
|
public function convert(array $data, object $object, array $tags = []): object |
|
|
|
{ |
|
|
|
{ |
|
|
|
$tags = empty($tags) ? ['default'] : $tags; |
|
|
|
$tags = empty($tags) ? ['default'] : $tags; |
|
|
|
$reflectionObject = new \ReflectionObject($object); |
|
|
|
$reflectionObject = new \ReflectionObject($object); |
|
|
|
|
|
|
|
|
|
|
|
$tags = $this->processTags($object, $data, $tags); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->processClassTransformers($reflectionObject, $data, $tags); |
|
|
|
$this->processClassTransformers($reflectionObject, $data, $tags); |
|
|
|
if (is_object($data)) { |
|
|
|
if (is_object($data)) { |
|
|
|
return $data; |
|
|
|
return $data; |
|
|
@ -189,8 +192,8 @@ class Data2DtoConverter |
|
|
|
protected function processTags(object $object, array $data, array $tags): array |
|
|
|
protected function processTags(object $object, array $data, array $tags): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$classExtractor = new ClassExtractor($object::class); |
|
|
|
$classExtractor = new ClassExtractor($object::class); |
|
|
|
/** @var TagsResolver $tagsMeta */ |
|
|
|
/** @var HandleTags $tagsMeta */ |
|
|
|
if ($tagsMeta = $classExtractor->fetch(TagsResolver::class)) { |
|
|
|
if ($tagsMeta = $classExtractor->fetch(HandleTags::class)) { |
|
|
|
if (method_exists($object, $tagsMeta->method)) { |
|
|
|
if (method_exists($object, $tagsMeta->method)) { |
|
|
|
$reflectionMethod = new \ReflectionMethod($object, $tagsMeta->method); |
|
|
|
$reflectionMethod = new \ReflectionMethod($object, $tagsMeta->method); |
|
|
|
if (!$reflectionMethod->isPublic()) { |
|
|
|
if (!$reflectionMethod->isPublic()) { |
|
|
|