Skip to content

Commit 258fd65

Browse files
committed
Using return value from populate()
1 parent ff20719 commit 258fd65

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/MapperInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
interface MapperInterface
2323
{
2424
/**
25+
* Load the "to object" and return it.
26+
*
27+
* This method should load (e.g. from the database) or instantiate the "to object".
28+
* Avoid populating any properties except for an identifier.
29+
*
2530
* @param TFrom $from
2631
* @param class-string<TTo> $toClass
2732
*
@@ -30,6 +35,10 @@ interface MapperInterface
3035
public function load(object $from, string $toClass, array $context): object;
3136

3237
/**
38+
* Populate the data onto the "to object" from the "from object".
39+
*
40+
* Receives the "to object" returned from load().
41+
*
3342
* @param TFrom $from
3443
* @param TTo $to
3544
*

src/MicroMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function map(object $from, string $toClass, array $context = []): object
6868

6969
// avoid fully populated objects if max depth is reached
7070
if (null === $this->maxDepth || $this->currentDepth < $this->maxDepth) {
71-
$mapperConfig->getMapper()->populate($from, $toObject, $context);
71+
$toObject = $mapperConfig->getMapper()->populate($from, $toObject, $context);
7272
}
7373

7474
unset($this->objectHashes[spl_object_hash($from)]);

0 commit comments

Comments
 (0)