Skip to content

Commit

Permalink
Merge branch 'main' into feat/project-reward-claims
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Dec 24, 2024
2 parents d82f244 + 029f825 commit cb23aa5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ services:

App\Mapping\AutoMapper:
arguments:
- '%kernel.cache_dir%'
- !tagged 'app.mapping.map_provider'

# add more service definitions when explicit configuration is needed
Expand Down
14 changes: 10 additions & 4 deletions src/Mapping/AutoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@

class AutoMapper implements AutoMapperInterface
{
public const SKIP_NULL_VALUES = 'skip_null_values';
public const CACHE_DIR = 'automapper';

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

private AutoMapperInterface $innerMapper;

public function __construct(
iterable $mapProviders,
?string $cacheDirectory = null,
iterable $mapProviders = [],
) {
$this->innerMapper = InnerMapper::create(
providers: \iterator_to_array($mapProviders)
cacheDirectory: \sprintf('%s%s%s', $cacheDirectory, \DIRECTORY_SEPARATOR, self::CACHE_DIR),
providers: $mapProviders,
);
}

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

Expand Down

0 comments on commit cb23aa5

Please sign in to comment.