-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCompiledMapper.php
37 lines (30 loc) · 1.06 KB
/
CompiledMapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace Kiboko\Component\FastMap;
use Kiboko\Component\FastMap\Compiler\Compiler;
use Kiboko\Contract\Mapping\Compiler\CompilationContextInterface;
use Kiboko\Contract\Mapping\MapperInterface;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
final class CompiledMapper implements MapperInterface
{
/** @var iterable<MapperInterface> */
private readonly iterable $mappers;
private MapperInterface $compiledMapper;
public function __construct(
private readonly Compiler $compiler,
private readonly CompilationContextInterface $compilationContext,
MapperInterface ...$mappers
) {
$this->mappers = $mappers;
}
public function __invoke($input, $output, PropertyPathInterface $outputPath)
{
if (null === $this->compiledMapper) {
$this->compiledMapper = $this->compiler->compile(
$this->compilationContext,
...$this->mappers
);
}
return ($this->compiledMapper)($input, $output, $outputPath);
}
}