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
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public const FILE_PREFIX = 'Customers'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface |
22
|
|
|
*/ |
23
|
|
|
protected $repository; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface> |
27
|
|
|
*/ |
28
|
|
|
protected $filterPlugins; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataExpanderInterface> |
32
|
|
|
*/ |
33
|
|
|
protected $expanderPlugins; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \SprykerEco\Zed\Minubo\Business\Writer\WriterInterface |
37
|
|
|
*/ |
38
|
|
|
protected $writer; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param \SprykerEco\Zed\Minubo\Persistence\MinuboRepositoryInterface $repository |
42
|
|
|
* @param array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface> $filterPlugins |
43
|
|
|
* @param array<\SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataExpanderInterface> $expanderPlugins |
44
|
|
|
* @param \SprykerEco\Zed\Minubo\Business\Writer\WriterInterface $writer |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
MinuboRepositoryInterface $repository, |
48
|
|
|
array $filterPlugins, |
49
|
|
|
array $expanderPlugins, |
50
|
|
|
WriterInterface $writer |
51
|
|
|
) { |
52
|
|
|
$this->repository = $repository; |
53
|
|
|
$this->filterPlugins = $filterPlugins; |
54
|
|
|
$this->expanderPlugins = $expanderPlugins; |
55
|
|
|
$this->writer = $writer; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function exportData(): void |
62
|
|
|
{ |
63
|
|
|
$customers = $this->repository |
64
|
|
|
->getCustomerDataUpdatedSinceLastRun(); |
65
|
|
|
|
66
|
|
|
$customers = $this->filterData($customers); |
67
|
|
|
|
68
|
|
|
$customers = $this->expandData($customers); |
69
|
|
|
|
70
|
|
|
$this->writer->writeData($customers, static::FILE_PREFIX); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array<mixed> $customers |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
protected function filterData(array $customers): array |
79
|
|
|
{ |
80
|
|
|
foreach ($customers as $key => $data) { |
81
|
|
|
foreach ($this->filterPlugins as $filter) { |
82
|
|
|
$customers[$key] = $filter->filterData($customers[$key]); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $customers; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array<mixed> $customers |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
protected function expandData(array $customers): array |
95
|
|
|
{ |
96
|
|
|
foreach ($customers as $key => $data) { |
97
|
|
|
foreach ($this->expanderPlugins as $expander) { |
98
|
|
|
$customers[$key] = $expander->expandData($customers[$key]); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $customers; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|