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