1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mathielen\ImportEngine\Importer; |
4
|
|
|
|
5
|
|
|
use Mathielen\ImportEngine\Filter\Filters; |
6
|
|
|
use Mathielen\ImportEngine\Storage\StorageInterface; |
7
|
|
|
use Mathielen\ImportEngine\Transformation\Transformation; |
8
|
|
|
use Mathielen\ImportEngine\Validation\ValidationInterface; |
9
|
|
|
use Mathielen\ImportEngine\Validation\DummyValidation; |
10
|
|
|
|
11
|
|
|
class Importer implements ImporterInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var StorageInterface |
15
|
|
|
*/ |
16
|
|
|
private $sourceStorage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var StorageInterface |
20
|
|
|
*/ |
21
|
|
|
private $targetStorage; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ValidationInterface |
25
|
|
|
*/ |
26
|
|
|
private $validation; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Transformation |
30
|
|
|
*/ |
31
|
|
|
private $transformation; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Filters |
35
|
|
|
*/ |
36
|
|
|
private $filters; |
37
|
|
|
|
38
|
|
|
private $context; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return \Mathielen\ImportEngine\Importer\Importer |
42
|
|
|
*/ |
43
|
21 |
|
public static function build(StorageInterface $targetStorage) |
44
|
|
|
{ |
45
|
21 |
|
return new self($targetStorage); |
46
|
|
|
} |
47
|
|
|
|
48
|
21 |
|
public function __construct(StorageInterface $targetStorage) |
49
|
|
|
{ |
50
|
21 |
|
$this->targetStorage = $targetStorage; |
51
|
|
|
|
52
|
21 |
|
$this->validation(new DummyValidation()); |
53
|
21 |
|
$this->transformation(new Transformation()); |
54
|
21 |
|
$this->filters(new Filters()); |
55
|
21 |
|
} |
56
|
|
|
|
57
|
|
|
public function setContext($context) |
58
|
|
|
{ |
59
|
|
|
$this->context = $context; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function getContext() |
63
|
|
|
{ |
64
|
1 |
|
return $this->context; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return StorageInterface |
69
|
|
|
*/ |
70
|
11 |
|
public function targetStorage() |
71
|
|
|
{ |
72
|
11 |
|
return $this->targetStorage; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return ValidationInterface |
77
|
|
|
*/ |
78
|
21 |
|
public function validation(ValidationInterface $validation = null) |
79
|
|
|
{ |
80
|
21 |
|
if ($validation) { |
81
|
21 |
|
$this->validation = $validation; |
82
|
|
|
} |
83
|
|
|
|
84
|
21 |
|
return $this->validation; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return \Mathielen\ImportEngine\Transformation\Transformation |
89
|
|
|
*/ |
90
|
21 |
|
public function transformation(Transformation $transformation = null) |
91
|
|
|
{ |
92
|
21 |
|
if ($transformation) { |
93
|
21 |
|
$this->transformation = $transformation; |
94
|
|
|
} |
95
|
|
|
|
96
|
21 |
|
return $this->transformation; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return \Mathielen\ImportEngine\Filter\Filters |
101
|
|
|
*/ |
102
|
21 |
|
public function filters(Filters $filters = null) |
103
|
|
|
{ |
104
|
21 |
|
if ($filters) { |
105
|
21 |
|
$this->filters = $filters; |
106
|
|
|
} |
107
|
|
|
|
108
|
21 |
|
return $this->filters; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return StorageInterface |
113
|
|
|
*/ |
114
|
1 |
|
public function getSourceStorage() |
115
|
|
|
{ |
116
|
1 |
|
return $this->sourceStorage; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return \Mathielen\ImportEngine\Importer\Importer |
121
|
|
|
*/ |
122
|
1 |
|
public function setSourceStorage(StorageInterface $sourceStorage) |
123
|
|
|
{ |
124
|
1 |
|
$this->sourceStorage = $sourceStorage; |
125
|
|
|
|
126
|
1 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|