1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oliverde8\Component\PhpEtl\ChainOperation; |
4
|
|
|
|
5
|
|
|
use Oliverde8\Component\PhpEtl\ChainProcessor; |
6
|
|
|
use Oliverde8\Component\PhpEtl\Item\DataItemInterface; |
7
|
|
|
use Oliverde8\Component\PhpEtl\Item\ItemInterface; |
8
|
|
|
use Oliverde8\Component\PhpEtl\Item\StopItem; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ChainSplitOperation |
12
|
|
|
* |
13
|
|
|
* @author de Cramer Oliver<[email protected]> |
14
|
|
|
* @copyright 2018 Oliverde8 |
15
|
|
|
* @package Oliverde8\Component\PhpEtl\ChainOperation |
16
|
|
|
*/ |
17
|
|
|
class ChainSplitOperation extends AbstractChainOperation implements DataChainOperationInterface |
18
|
|
|
{ |
19
|
|
|
/** @var ChainProcessor[] */ |
20
|
|
|
protected $chainProcessors; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ChainSplitOperation constructor. |
24
|
|
|
* |
25
|
|
|
* @param ChainProcessor[] $chainProcessors |
26
|
|
|
*/ |
27
|
2 |
|
public function __construct(array $chainProcessors) |
28
|
|
|
{ |
29
|
2 |
|
$this->chainProcessors = $chainProcessors; |
30
|
2 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Process DataItems. |
34
|
|
|
* |
35
|
|
|
* @param DataItemInterface $item |
36
|
|
|
* @param array $context |
37
|
|
|
* |
38
|
|
|
* @return ItemInterface |
39
|
|
|
* @throws \Oliverde8\Component\PhpEtl\Exception\ChainOperationException |
40
|
|
|
*/ |
41
|
2 |
|
public function processData(DataItemInterface $item, array &$context) |
42
|
|
|
{ |
43
|
2 |
|
foreach ($this->chainProcessors as $chainProcessor) { |
44
|
2 |
|
$chainProcessor->processItem($item, 0, $context); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Nothing to process. |
48
|
2 |
|
return $item; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param StopItem $item |
53
|
|
|
* @param array $context |
54
|
|
|
* |
55
|
|
|
* @return StopItem |
56
|
|
|
* @throws \Oliverde8\Component\PhpEtl\Exception\ChainOperationException |
57
|
|
|
*/ |
58
|
1 |
|
public function processStop(StopItem $item, array &$context) |
59
|
|
|
{ |
60
|
1 |
|
foreach ($this->chainProcessors as $chainProcessor) { |
61
|
1 |
|
$result = $chainProcessor->processItem($item, 0, $context); |
62
|
|
|
|
63
|
1 |
|
if ($result !== $item) { |
64
|
|
|
// Return a new stop item in order to continue flushing out data with stop items. |
65
|
1 |
|
$item = new StopItem(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return $item; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|