1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Cli\Configuration\Subject |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli\Configuration; |
22
|
|
|
|
23
|
|
|
use JMS\Serializer\Annotation\Type; |
24
|
|
|
use JMS\Serializer\Annotation\SerializedName; |
25
|
|
|
use TechDivision\Import\ConfigurationInterface; |
26
|
|
|
use TechDivision\Import\Configuration\SubjectConfigurationInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The subject configuration implementation. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
35
|
|
|
* @link http://www.techdivision.com |
36
|
|
|
*/ |
37
|
|
|
class Subject implements SubjectConfigurationInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The trait that provides parameter handling functionality. |
42
|
|
|
* |
43
|
|
|
* @var \TechDivision\Import\Cli\Configuration\ParamsTrait |
44
|
|
|
*/ |
45
|
|
|
use ParamsTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The subject's class name. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
* @Type("string") |
52
|
|
|
* @SerializedName("class-name") |
53
|
|
|
*/ |
54
|
|
|
protected $className; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The subject's processor type to use. |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
* @Type("string") |
61
|
|
|
* @SerializedName("processor-factory") |
62
|
|
|
*/ |
63
|
|
|
protected $processorFactory; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* The subject's utility class with the SQL statements to use. |
67
|
|
|
* |
68
|
|
|
* @var string |
69
|
|
|
* @Type("string") |
70
|
|
|
* @SerializedName("utility-class-name") |
71
|
|
|
*/ |
72
|
|
|
protected $utilityClassName; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The file prefix for import files. |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
* @Type("string") |
79
|
|
|
*/ |
80
|
|
|
protected $prefix = 'magento-import'; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The array with the subject's observers. |
84
|
|
|
* |
85
|
|
|
* @var array |
86
|
|
|
* @Type("array") |
87
|
|
|
*/ |
88
|
|
|
protected $observers = array(); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* The array with the subject's callbacks. |
92
|
|
|
* |
93
|
|
|
* @var array |
94
|
|
|
* @Type("array<string, array>") |
95
|
|
|
*/ |
96
|
|
|
protected $callbacks = array(); |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* A reference to the parent configuration instance. |
100
|
|
|
* |
101
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
102
|
|
|
*/ |
103
|
|
|
protected $configuration; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* The flag to signal that the subjects needs a OK file to be processed or not. |
107
|
|
|
* |
108
|
|
|
* @var boolean |
109
|
|
|
* @Type("boolean") |
110
|
|
|
* @SerializedName("ok-file-needed") |
111
|
|
|
*/ |
112
|
|
|
protected $okFileNeeded = false; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return's the multiple field delimiter character to use, default value is comma (,). |
116
|
|
|
* |
117
|
|
|
* @return string The multiple field delimiter character |
118
|
|
|
*/ |
119
|
|
|
public function getMultipleFieldDelimiter() |
120
|
|
|
{ |
121
|
|
|
return $this->getConfiguration()->getMultipleFieldDelimiter(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Return's the delimiter character to use, default value is comma (,). |
126
|
|
|
* |
127
|
|
|
* @return string The delimiter character |
128
|
|
|
*/ |
129
|
|
|
public function getDelimiter() |
130
|
|
|
{ |
131
|
|
|
return $this->getConfiguration()->getDelimiter(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* The enclosure character to use, default value is double quotation ("). |
136
|
|
|
* |
137
|
|
|
* @return string The enclosure character |
138
|
|
|
*/ |
139
|
|
|
public function getEnclosure() |
140
|
|
|
{ |
141
|
|
|
return $this->getConfiguration()->getEnclosure(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* The escape character to use, default value is backslash (\). |
146
|
|
|
* |
147
|
|
|
* @return string The escape character |
148
|
|
|
*/ |
149
|
|
|
public function getEscape() |
150
|
|
|
{ |
151
|
|
|
return $this->getConfiguration()->getEscape(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* The file encoding of the CSV source file, default value is UTF-8. |
156
|
|
|
* |
157
|
|
|
* @return string The charset used by the CSV source file |
158
|
|
|
*/ |
159
|
|
|
public function getFromCharset() |
160
|
|
|
{ |
161
|
|
|
return $this->getConfiguration()->getFromCharset(); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* The file encoding of the CSV targetfile, default value is UTF-8. |
166
|
|
|
* |
167
|
|
|
* @return string The charset used by the CSV target file |
168
|
|
|
*/ |
169
|
|
|
public function getToCharset() |
170
|
|
|
{ |
171
|
|
|
return $this->getConfiguration()->getToCharset(); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* The file mode of the CSV target file, either one of write or append, default is write. |
176
|
|
|
* |
177
|
|
|
* @return string The file mode of the CSV target file |
178
|
|
|
*/ |
179
|
|
|
public function getFileMode() |
180
|
|
|
{ |
181
|
|
|
return $this->getConfiguration()->getFileMode(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Queries whether or not strict mode is enabled or not, default is TRUE. |
186
|
|
|
* |
187
|
|
|
* @return boolean TRUE if strict mode is enabled, else FALSE |
188
|
|
|
*/ |
189
|
|
|
public function isStrictMode() |
190
|
|
|
{ |
191
|
|
|
return $this->getConfiguration()->isStrictMode(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Return's the subject's source date format to use. |
196
|
|
|
* |
197
|
|
|
* @return string The source date format |
198
|
|
|
*/ |
199
|
|
|
public function getSourceDateFormat() |
200
|
|
|
{ |
201
|
|
|
return $this->getConfiguration()->getSourceDateFormat(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Return's the source directory that has to be watched for new files. |
206
|
|
|
* |
207
|
|
|
* @return string The source directory |
208
|
|
|
*/ |
209
|
|
|
public function getSourceDir() |
210
|
|
|
{ |
211
|
|
|
return $this->getConfiguration()->getSourceDir(); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Return's the target directory with the files that has been imported. |
216
|
|
|
* |
217
|
|
|
* @return string The target directory |
218
|
|
|
*/ |
219
|
|
|
public function getTargetDir() |
220
|
|
|
{ |
221
|
|
|
return $this->getConfiguration()->getTargetDir(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Queries whether or not debug mode is enabled or not, default is TRUE. |
226
|
|
|
* |
227
|
|
|
* @return boolean TRUE if debug mode is enabled, else FALSE |
228
|
|
|
*/ |
229
|
|
|
public function isDebugMode() |
230
|
|
|
{ |
231
|
|
|
return $this->getConfiguration()->isDebugMode(); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Return's the subject's class name. |
236
|
|
|
* |
237
|
|
|
* @return string The subject's class name |
238
|
|
|
*/ |
239
|
|
|
public function getClassName() |
240
|
|
|
{ |
241
|
|
|
return $this->className; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Return's the subject's processor factory type to use. |
246
|
|
|
* |
247
|
|
|
* @return string The subject's processor factory type |
248
|
|
|
*/ |
249
|
|
|
public function getProcessorFactory() |
250
|
|
|
{ |
251
|
|
|
return $this->processorFactory; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Return's the utility class with the SQL statements to use. |
256
|
|
|
* |
257
|
|
|
* @return string The utility class name |
258
|
|
|
*/ |
259
|
|
|
public function getUtilityClassName() |
260
|
|
|
{ |
261
|
|
|
return $this->utilityClassName; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Set's the reference to the configuration instance. |
266
|
|
|
* |
267
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
268
|
|
|
* |
269
|
|
|
* @return void |
270
|
|
|
*/ |
271
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
272
|
|
|
{ |
273
|
|
|
$this->configuration = $configuration; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Return's the reference to the configuration instance. |
278
|
|
|
* |
279
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
280
|
|
|
*/ |
281
|
|
|
public function getConfiguration() |
282
|
|
|
{ |
283
|
|
|
return $this->configuration; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Set's the prefix for the import files. |
288
|
|
|
* |
289
|
|
|
* @param string $prefix The prefix |
290
|
|
|
* |
291
|
|
|
* @return void |
292
|
|
|
*/ |
293
|
|
|
public function setPrefix($prefix) |
294
|
|
|
{ |
295
|
|
|
$this->prefix = $prefix; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Return's the prefix for the import files. |
300
|
|
|
* |
301
|
|
|
* @return string The prefix |
302
|
|
|
*/ |
303
|
|
|
public function getPrefix() |
304
|
|
|
{ |
305
|
|
|
return $this->prefix; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Return's the array with the subject's observers. |
310
|
|
|
* |
311
|
|
|
* @return array The subject's observers |
312
|
|
|
*/ |
313
|
|
|
public function getObservers() |
314
|
|
|
{ |
315
|
|
|
return $this->observers; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Return's the array with the subject's callbacks. |
320
|
|
|
* |
321
|
|
|
* @return array The subject's callbacks |
322
|
|
|
*/ |
323
|
|
|
public function getCallbacks() |
324
|
|
|
{ |
325
|
|
|
return $this->callbacks; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Set's the flag to signal that the an OK file is needed for the subject |
330
|
|
|
* to be processed. |
331
|
|
|
* |
332
|
|
|
* @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE |
333
|
|
|
* |
334
|
|
|
* @return void |
335
|
|
|
*/ |
336
|
|
|
public function setOkFileNeeded($okFileNeeded) |
337
|
|
|
{ |
338
|
|
|
$this->okFileNeeded = $okFileNeeded; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Queries whether or not that the subject needs an OK file to be processed. |
343
|
|
|
* |
344
|
|
|
* @return boolean TRUE if the subject needs an OK file, else FALSE |
345
|
|
|
*/ |
346
|
|
|
public function isOkFileNeeded() |
347
|
|
|
{ |
348
|
|
|
return $this->okFileNeeded; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|