1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Minubo\Business\Exporter; |
9
|
|
|
|
10
|
|
|
use SprykerEco\Zed\Minubo\Business\Writer\WriterInterface; |
11
|
|
|
use SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface; |
12
|
|
|
|
13
|
|
|
class CustomerDataExporter implements DataExporterInterface |
14
|
|
|
{ |
15
|
|
|
const FILE_PREFIX = 'Customers'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface |
19
|
|
|
*/ |
20
|
|
|
protected $repository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface[] |
24
|
|
|
*/ |
25
|
|
|
protected $filterPlugins; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataExpanderInterface[] |
29
|
|
|
*/ |
30
|
|
|
protected $expanderPlugins; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \SprykerEco\Zed\Minubo\Business\Writer\WriterInterface |
34
|
|
|
*/ |
35
|
|
|
protected $writer; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param \SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface $repository |
39
|
|
|
* @param \SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface[] $filterPlugins |
40
|
|
|
* @param \SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataExpanderInterface[] $expanderPlugins |
41
|
|
|
* @param \SprykerEco\Zed\Minubo\Business\Writer\WriterInterface $writer |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
MinuboRepositoryInterface $repository, |
45
|
|
|
array $filterPlugins, |
46
|
|
|
array $expanderPlugins, |
47
|
|
|
WriterInterface $writer |
48
|
|
|
) { |
49
|
|
|
|
50
|
|
|
$this->repository = $repository; |
51
|
|
|
$this->filterPlugins = $filterPlugins; |
52
|
|
|
$this->expanderPlugins = $expanderPlugins; |
53
|
|
|
$this->writer = $writer; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function exportData(): void |
60
|
|
|
{ |
61
|
|
|
$customers = $this->repository |
62
|
|
|
->getCustomerDataUpdatedSinceLastRun(); |
63
|
|
|
|
64
|
|
|
$customers = $this->filterData($customers); |
65
|
|
|
|
66
|
|
|
$customers = $this->expandData($customers); |
67
|
|
|
|
68
|
|
|
$this->writer->writeData($customers, static::FILE_PREFIX); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param array $customers |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
protected function filterData(array $customers): array |
77
|
|
|
{ |
78
|
|
|
foreach ($customers as $key => $data) { |
79
|
|
|
foreach ($this->filterPlugins as $filter) { |
80
|
|
|
$customers[$key] = $filter->filterData($customers[$key]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $customers; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param array $customers |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
protected function expandData(array $customers): array |
93
|
|
|
{ |
94
|
|
|
foreach ($customers as $key => $data) { |
95
|
|
|
foreach ($this->expanderPlugins as $expander) { |
96
|
|
|
$customers[$key] = $expander->expandData($customers[$key]); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $customers; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|