1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maketok\DataMigration\Unit\Type; |
4
|
|
|
|
5
|
|
|
use Maketok\DataMigration\HashmapInterface; |
6
|
|
|
use Maketok\DataMigration\Storage\Filesystem\Resource; |
7
|
|
|
use Maketok\DataMigration\Storage\Filesystem\ResourceInterface; |
8
|
|
|
use Maketok\DataMigration\Unit\AbstractUnit; |
9
|
|
|
use Maketok\DataMigration\Unit\ImportFileUnitInterface; |
10
|
|
|
|
11
|
|
|
abstract class ImportFileUnit extends AbstractUnit implements ImportFileUnitInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string|callable |
15
|
|
|
*/ |
16
|
|
|
protected $isEntityCondition; |
17
|
|
|
/** |
18
|
|
|
* @var array|string[]|callable[] |
19
|
|
|
*/ |
20
|
|
|
protected $contributions = []; |
21
|
|
|
/** |
22
|
|
|
* @var array|string[]|callable[] |
23
|
|
|
*/ |
24
|
|
|
protected $writeConditions = []; |
25
|
|
|
/** |
26
|
|
|
* @var array|string[]|callable[] |
27
|
|
|
*/ |
28
|
|
|
protected $validationRules = []; |
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $mapping = []; |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $tmpFileName; |
37
|
|
|
/** |
38
|
|
|
* @var ResourceInterface |
39
|
|
|
*/ |
40
|
|
|
protected $filesystem; |
41
|
|
|
/** |
42
|
|
|
* @var HashmapInterface[] |
43
|
|
|
*/ |
44
|
|
|
protected $hashmaps; |
45
|
|
|
|
46
|
55 |
|
public function __construct($code) |
47
|
|
|
{ |
48
|
55 |
|
parent::__construct($code); |
49
|
55 |
|
$this->filesystem = new Resource(); |
50
|
55 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
29 |
|
public function getMapping() |
56
|
|
|
{ |
57
|
29 |
|
return $this->mapping; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
25 |
|
public function setMapping(array $mapping) |
64
|
|
|
{ |
65
|
25 |
|
$this->mapping = $mapping; |
66
|
25 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
6 |
|
public function getIsEntityCondition() |
72
|
|
|
{ |
73
|
6 |
|
return $this->isEntityCondition; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
20 |
|
public function setIsEntityCondition($condition) |
80
|
|
|
{ |
81
|
20 |
|
$this->isEntityCondition = $condition; |
82
|
20 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc |
86
|
|
|
*/ |
87
|
8 |
|
public function getContributions() |
88
|
|
|
{ |
89
|
8 |
|
return $this->contributions; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
9 |
|
public function addContribution($contribution) |
96
|
|
|
{ |
97
|
9 |
|
$this->contributions[] = $contribution; |
98
|
9 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
13 |
|
public function getWriteConditions() |
104
|
|
|
{ |
105
|
13 |
|
return $this->writeConditions; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
5 |
|
public function addWriteCondition($condition) |
112
|
|
|
{ |
113
|
5 |
|
$this->writeConditions[] = $condition; |
114
|
5 |
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritdoc} |
118
|
|
|
*/ |
119
|
31 |
|
public function getFilesystem() |
120
|
|
|
{ |
121
|
31 |
|
return $this->filesystem; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
21 |
|
public function setFilesystem(ResourceInterface $filesystem) |
128
|
|
|
{ |
129
|
21 |
|
$this->filesystem = $filesystem; |
130
|
21 |
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
*/ |
135
|
31 |
|
public function getTmpFileName() |
136
|
|
|
{ |
137
|
31 |
|
return $this->tmpFileName; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritdoc} |
142
|
|
|
*/ |
143
|
29 |
|
public function setTmpFileName($tmpFileName) |
144
|
|
|
{ |
145
|
29 |
|
$this->tmpFileName = $tmpFileName; |
146
|
29 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* {@inheritdoc} |
150
|
|
|
*/ |
151
|
8 |
|
public function getValidationRules() |
152
|
|
|
{ |
153
|
8 |
|
return $this->validationRules; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* {@inheritdoc} |
158
|
|
|
*/ |
159
|
4 |
|
public function addValidationRule($condition) |
160
|
|
|
{ |
161
|
4 |
|
$this->validationRules[] = $condition; |
162
|
4 |
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* close IO if it was not closed |
166
|
|
|
*/ |
167
|
54 |
|
public function __destruct() |
168
|
|
|
{ |
169
|
54 |
|
if (isset($this->filesystem) && $this->filesystem->isActive()) { |
170
|
|
|
$this->filesystem->close(); |
171
|
|
|
} |
172
|
54 |
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* {@inheritdoc} |
176
|
|
|
*/ |
177
|
8 |
|
public function addHashmap(HashmapInterface $hashmap) |
178
|
|
|
{ |
179
|
8 |
|
$this->hashmaps[$hashmap->getCode()] = $hashmap; |
180
|
8 |
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* {@inheritdoc} |
184
|
|
|
*/ |
185
|
24 |
|
public function getHashmaps() |
186
|
|
|
{ |
187
|
24 |
|
return $this->hashmaps; |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|