-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProjectionDocumentProvider.php
More file actions
44 lines (39 loc) · 1.18 KB
/
ProjectionDocumentProvider.php
File metadata and controls
44 lines (39 loc) · 1.18 KB
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
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace MsgPhp\Domain\Projection;
/**
* @author Roland Franssen <[email protected]>
*
* @template T of object
*/
final class ProjectionDocumentProvider implements \IteratorAggregate
{
/** @var iterable<int, callable():T> */
private $dataProviders;
/** @var callable(T):array */
private $transformer;
/** @var callable(T):string */
private $typeResolver;
/**
* @param iterable<int, callable():T> $dataProviders
* @param callable(T):array $transformer
* @param callable(T):string $typeResolver
*/
public function __construct(iterable $dataProviders, callable $transformer, callable $typeResolver)
{
$this->dataProviders = $dataProviders;
$this->transformer = $transformer;
$this->typeResolver = $typeResolver;
}
/**
* @return \Traversable<string, array>
*/
public function getIterator(): \Traversable
{
foreach ($this->dataProviders as $dataProvider) {
foreach ($dataProvider() as $object) {
yield ($this->typeResolver)($object) => ($this->transformer)($object);
}
}
}
}