Skip to content

Commit

Permalink
Add default mapping context
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Dec 24, 2024
1 parent 34a2885 commit ee31334
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Mapping/AutoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class AutoMapper implements AutoMapperInterface
{
public const CACHE_DIR = 'automapper';

public const DEFAULT_CONTEXT = [
'skip_null_values' => true
];

private AutoMapperInterface $innerMapper;

public function __construct(
Expand All @@ -23,6 +27,11 @@ public function __construct(

public function map(array|object $source, string|array|object $target, array $context = []): array|object|null
{
$context = [
...self::DEFAULT_CONTEXT,
...$context,
];

return $this->innerMapper->map($source, $target, $context);
}
}

0 comments on commit ee31334

Please sign in to comment.