Skip to content

Commit 9cff869

Browse files
committed
Added ArrayMapper implementation
1 parent 7e8f697 commit 9cff869

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Mapping/Composite/ArrayMapper.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ public function __invoke($input, $output, PropertyPathInterface $outputPath)
4242

4343
public function compile(Node\Expr $outputNode): array
4444
{
45-
// TODO: Implement compile() method.
45+
return array_merge(
46+
...$this->compileMappers($outputNode)
47+
);
48+
}
49+
50+
private function compileMappers(Node\Expr $outputNode): iterable
51+
{
52+
foreach ($this->fields as $mapper) {
53+
if (!$mapper instanceof Contracts\CompilableInterface) {
54+
throw new \RuntimeException(strtr(
55+
'Expected a %expected%, but got an object of type %actual%.',
56+
[
57+
'%expected%' => Contracts\CompilableInterface::class,
58+
'%actual%' => get_class($mapper),
59+
]
60+
));
61+
}
62+
63+
yield $mapper->compile($outputNode);
64+
}
4665
}
4766
}

0 commit comments

Comments
 (0)