Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code examples in the readme #3

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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