Skip to content

Commit

Permalink
Improve Symfony bundle documentation (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Dec 14, 2023
1 parent 72603a6 commit 275cb6f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion docs/symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,42 @@ Possible properties:
- `cache_dir` (default: `%kernel.cache_dir%/automapper`): This setting allows you to customize the output directory
for generated mappers;
- `mappings`: This option allows you to customize Mapper metadata, you have to specify `source` & `target` data types
and related configuration using `pass` field. This configuration should implements `AutoMapper\Bundle\Configuration\ConfigurationPassInterface`.
and related configuration using `pass` field. This configuration should implements `AutoMapper\Bundle\Configuration\MapperConfigurationInterface`.
- `allow_readonly_target_to_populate` (default: `false`): Will throw an exception if you use a readonly class as target
to populate if set to `false`.

### MapperConfigurationInterface

You can add some metadata to customize a transformation. Here is an example:

```php
class UserMapperConfiguration implements MapperConfigurationInterface
{
public function getSource(): string
{
return User::class;
}

public function getTarget(): string
{
return UserDTO::class;
}

public function process(MapperGeneratorMetadataInterface $metadata): void
{
$metadata->forMember('yearOfBirth', function (User $user) {
return ((int) date('Y')) - ((int) $user->age);
return ((int) date('Y')) - ((int) $user->age);
});
}
}
```

Here you have to inherit the `MapperConfigurationInterface` interface, that ways it will autoconfigure your
transformation for a given source & target. And in the `process` method you will add or overwrite fields to map.
The fields you give onto the `forMember` method are target fields and the callback will always give you the source
object.

### Normalizer Bridge 🌁
A Normalizer Bridge is available, aiming to be 100% feature compatible with the ObjectNormalizer of the
``symfony/serializer`` component. The goal of this bridge **is not to replace the ObjectNormalizer** but rather
Expand Down

0 comments on commit 275cb6f

Please sign in to comment.