Skip to content

Commit

Permalink
Merge pull request #3 from jdreesen/patch-1
Browse files Browse the repository at this point in the history
Fix code examples in the readme
  • Loading branch information
bocharsky-bw authored Sep 7, 2023
2 parents ac66363 + fb3df0c commit fccf7f1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class DragonEntityToDtoMapper implements MapperInterface

public function populate(object $from, object $to, array $context): object
{
$dto = $from;
$entity = $to;
$entity = $from;
$dto = $to;

$dto->name = $entity->getName();
$dto->firePower = $entity->getFirePower();

return $entity;
return $dto;
}
}
```
Expand Down Expand Up @@ -100,16 +100,16 @@ class DragonEntityToApiMapper implements MapperInterface

public function populate(object $from, object $to, array $context): object
{
$dto = $from;
$entity = $to;
$entity = $from;
$dto = $to;
// helps your editor know the types
assert($dto instanceof DragonApi);
assert($entity instanceof Dragon);
assert($dto instanceof DragonApi);

$dto->name = $entity->getName();
$dto->firePower = $entity->getFirePower();

return $entity;
return $dto;
}
}
```
Expand All @@ -123,7 +123,7 @@ The mapper class has three parts:
3. `populate()` method: populates the "to" object with data from the "from"
object.

### Step 2: Use The MicroMapper Service
### Step 2: Use the MicroMapper Service

To use the mapper, you can fetch the `MicroMapperInterface` service. For
example, from a controller:
Expand All @@ -134,6 +134,7 @@ example, from a controller:
namespace App\Controller;

use App\Entity\Dragon;
use App\ApiResource\DragonApi;
use Symfonycasts\MicroMapper\MicroMapperInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -226,7 +227,7 @@ class TreasureEntityToApiMapper implements MapperInterface

// ... map all the properties

return $entity;
return $dto;
}
}
```
Expand Down Expand Up @@ -264,7 +265,7 @@ class DragonEntityToApiMapper implements MapperInterface
}
$dto->treasures = $treasuresApis;

return $entity;
return $dto;
}
}
```
Expand Down Expand Up @@ -299,7 +300,7 @@ class TreasureEntityToApiMapper implements MapperInterface
MicroMapperInterface::MAX_DEPTH => 1,
]);

return $entity;
return $dto;
}
}
```
Expand Down

0 comments on commit fccf7f1

Please sign in to comment.