Skip to content

Commit

Permalink
Using return value from populate()
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Aug 23, 2023
1 parent ff20719 commit 258fd65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/MapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TTo> $toClass
*
Expand All @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/MicroMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down

0 comments on commit 258fd65

Please sign in to comment.