diff --git a/src/MapperInterface.php b/src/MapperInterface.php index bd05f4e..484b2b3 100644 --- a/src/MapperInterface.php +++ b/src/MapperInterface.php @@ -22,6 +22,11 @@ interface MapperInterface { /** + * Load the "to object" and return it. + * + * This method should load (e.g. from the database) or instantiate the "to object". + * Avoid populating any properties except for an identifier. + * * @param TFrom $from * @param class-string $toClass * @@ -30,6 +35,10 @@ interface MapperInterface public function load(object $from, string $toClass, array $context): object; /** + * Populate the data onto the "to object" from the "from object". + * + * Receives the "to object" returned from load(). + * * @param TFrom $from * @param TTo $to * diff --git a/src/MicroMapper.php b/src/MicroMapper.php index 22551f1..c051319 100644 --- a/src/MicroMapper.php +++ b/src/MicroMapper.php @@ -68,7 +68,7 @@ public function map(object $from, string $toClass, array $context = []): object // avoid fully populated objects if max depth is reached if (null === $this->maxDepth || $this->currentDepth < $this->maxDepth) { - $mapperConfig->getMapper()->populate($from, $toObject, $context); + $toObject = $mapperConfig->getMapper()->populate($from, $toObject, $context); } unset($this->objectHashes[spl_object_hash($from)]);