Skip to content

Commit fccf7f1

Browse files
authored
Merge pull request #3 from jdreesen/patch-1
Fix code examples in the readme
2 parents ac66363 + fb3df0c commit fccf7f1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class DragonEntityToDtoMapper implements MapperInterface
2222

2323
public function populate(object $from, object $to, array $context): object
2424
{
25-
$dto = $from;
26-
$entity = $to;
25+
$entity = $from;
26+
$dto = $to;
2727

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

31-
return $entity;
31+
return $dto;
3232
}
3333
}
3434
```
@@ -100,16 +100,16 @@ class DragonEntityToApiMapper implements MapperInterface
100100

101101
public function populate(object $from, object $to, array $context): object
102102
{
103-
$dto = $from;
104-
$entity = $to;
103+
$entity = $from;
104+
$dto = $to;
105105
// helps your editor know the types
106-
assert($dto instanceof DragonApi);
107106
assert($entity instanceof Dragon);
107+
assert($dto instanceof DragonApi);
108108

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

112-
return $entity;
112+
return $dto;
113113
}
114114
}
115115
```
@@ -123,7 +123,7 @@ The mapper class has three parts:
123123
3. `populate()` method: populates the "to" object with data from the "from"
124124
object.
125125

126-
### Step 2: Use The MicroMapper Service
126+
### Step 2: Use the MicroMapper Service
127127

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

136136
use App\Entity\Dragon;
137+
use App\ApiResource\DragonApi;
137138
use Symfonycasts\MicroMapper\MicroMapperInterface;
138139
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
139140
use Symfony\Component\Routing\Annotation\Route;
@@ -226,7 +227,7 @@ class TreasureEntityToApiMapper implements MapperInterface
226227

227228
// ... map all the properties
228229

229-
return $entity;
230+
return $dto;
230231
}
231232
}
232233
```
@@ -264,7 +265,7 @@ class DragonEntityToApiMapper implements MapperInterface
264265
}
265266
$dto->treasures = $treasuresApis;
266267

267-
return $entity;
268+
return $dto;
268269
}
269270
}
270271
```
@@ -299,7 +300,7 @@ class TreasureEntityToApiMapper implements MapperInterface
299300
MicroMapperInterface::MAX_DEPTH => 1,
300301
]);
301302

302-
return $entity;
303+
return $dto;
303304
}
304305
}
305306
```

0 commit comments

Comments
 (0)