From cfce7d3c5e235459ab27860669755d254afb8bf0 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Wed, 13 Nov 2024 01:22:34 +0700 Subject: [PATCH] fix --- src/MapperFactory.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/MapperFactory.php b/src/MapperFactory.php index 0bcbf5a..320928b 100644 --- a/src/MapperFactory.php +++ b/src/MapperFactory.php @@ -179,10 +179,14 @@ class MapperFactory private ?TransformerRegistryInterface $transformerRegistry = null; + private ?ContainerInterface $propertyMapperLocator = null; + private ?PropertyMapperResolverInterface $propertyMapperResolver = null; private ?ObjectMapperTableFactoryInterface $objectMapperTableFactory = null; + private ?ContainerInterface $objectMapperLocator = null; + private ?ObjectMapperResolverInterface $objectMapperResolver = null; private ?PropertyReadInfoExtractorInterface $propertyReadInfoExtractor = null; @@ -443,7 +447,7 @@ protected function getObjectMapperTransformer(): TransformerInterface if (null === $this->objectMapperTransformer) { $this->objectMapperTransformer = new ObjectMapperTransformer( $this->getSubMapperFactory(), - $this->getTransformersLocator(), + $this->getObjectMapperLocator(), $this->getObjectMapperTableFactory(), $this->getObjectMapperResolver(), ); @@ -800,6 +804,23 @@ protected function getObjectMapperTableFactory(): ObjectMapperTableFactoryInterf return $this->objectMapperTableFactory; } + protected function getObjectMapperLocator(): ContainerInterface + { + if ($this->objectMapperLocator !== null) { + return $this->objectMapperLocator; + } + + $services = []; + + foreach ($this->objectMappers as $objectMapper) { + $service = $objectMapper['service']; + $class = $service::class; + $services[$class] = $service; + } + + return $this->objectMapperLocator = new ServiceLocator($services); + } + protected function getObjectMapperResolver(): ObjectMapperResolverInterface { if (null === $this->objectMapperResolver) { @@ -813,6 +834,10 @@ protected function getObjectMapperResolver(): ObjectMapperResolverInterface protected function getPropertyMapperLocator(): ContainerInterface { + if ($this->propertyMapperLocator !== null) { + return $this->propertyMapperLocator; + } + $services = []; foreach ($this->propertyMappers as $propertyMapper) { @@ -821,7 +846,7 @@ protected function getPropertyMapperLocator(): ContainerInterface $services[$class] = $service; } - return new ServiceLocator($services); + return $this->propertyMapperLocator = new ServiceLocator($services); } protected function getPropertyReadInfoExtractor(): PropertyReadInfoExtractorInterface