1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Configuration\Jms\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-configuration-jms |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Configuration\Jms\Configuration; |
22
|
|
|
|
23
|
|
|
use JMS\Serializer\Annotation\Type; |
24
|
|
|
use JMS\Serializer\Annotation\SerializedName; |
25
|
|
|
use JMS\Serializer\Annotation\PostDeserialize; |
26
|
|
|
use TechDivision\Import\ConfigurationInterface; |
27
|
|
|
use TechDivision\Import\Configuration\SubjectConfigurationInterface; |
28
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter; |
29
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter; |
30
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The subject configuration implementation. |
34
|
|
|
* |
35
|
|
|
* @author Tim Wagner <[email protected]> |
36
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
37
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
38
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
39
|
|
|
* @link http://www.techdivision.com |
40
|
|
|
*/ |
41
|
|
|
class Subject implements SubjectConfigurationInterface |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The trait that provides parameter handling functionality. |
46
|
|
|
* |
47
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
48
|
|
|
*/ |
49
|
|
|
use ParamsTrait; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The subject's unique DI identifier. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
* @Type("string") |
56
|
|
|
* @SerializedName("id") |
57
|
|
|
*/ |
58
|
|
|
protected $id; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The file prefix for import files. |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
* @Type("string") |
65
|
|
|
*/ |
66
|
|
|
protected $prefix = 'magento-import'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The file suffix for import files. |
70
|
|
|
* |
71
|
|
|
* @var string |
72
|
|
|
* @Type("string") |
73
|
|
|
*/ |
74
|
|
|
protected $suffix = 'csv'; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* The array with the subject's observers. |
78
|
|
|
* |
79
|
|
|
* @var array |
80
|
|
|
* @Type("array") |
81
|
|
|
*/ |
82
|
|
|
protected $observers = array(); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The array with the subject's callbacks. |
86
|
|
|
* |
87
|
|
|
* @var array |
88
|
|
|
* @Type("array<string, array>") |
89
|
|
|
*/ |
90
|
|
|
protected $callbacks = array(); |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* The array with the subject's frontend input callbacks. |
94
|
|
|
* |
95
|
|
|
* @var array |
96
|
|
|
* @Type("array<string, array>") |
97
|
|
|
* @SerializedName("frontend-input-callbacks") |
98
|
|
|
*/ |
99
|
|
|
protected $frontendInputCallbacks = array(); |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* A reference to the parent configuration instance. |
103
|
|
|
* |
104
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
105
|
|
|
*/ |
106
|
|
|
protected $configuration; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* The flag to signal that the subjects needs a OK file to be processed or not. |
110
|
|
|
* |
111
|
|
|
* @var boolean |
112
|
|
|
* @Type("boolean") |
113
|
|
|
* @SerializedName("ok-file-needed") |
114
|
|
|
*/ |
115
|
|
|
protected $okFileNeeded = false; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* The import adapter configuration instance. |
119
|
|
|
* |
120
|
|
|
* @var \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface |
121
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter") |
122
|
|
|
* @SerializedName("import-adapter") |
123
|
|
|
*/ |
124
|
|
|
protected $importAdapter; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* The export adapter configuration instance. |
128
|
|
|
* |
129
|
|
|
* @var \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface |
130
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter") |
131
|
|
|
* @SerializedName("export-adapter") |
132
|
|
|
*/ |
133
|
|
|
protected $exportAdapter; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* The filesystem adapter configuration instance. |
137
|
|
|
* |
138
|
|
|
* @var \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface |
139
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter") |
140
|
|
|
* @SerializedName("filesystem-adapter") |
141
|
|
|
*/ |
142
|
|
|
protected $filesystemAdapter; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Lifecycle callback that will be invoked after deserialization. |
146
|
|
|
* |
147
|
|
|
* @return void |
148
|
|
|
* @PostDeserialize |
149
|
|
|
*/ |
150
|
|
|
public function postDeserialize() |
151
|
|
|
{ |
152
|
|
|
|
153
|
|
|
// set a default import adatper if none has been configured |
154
|
|
|
if ($this->importAdapter === null) { |
155
|
|
|
$this->importAdapter = new ImportAdapter(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// set a default export adatper if none has been configured |
159
|
|
|
if ($this->exportAdapter === null) { |
160
|
|
|
$this->exportAdapter = new ExportAdapter(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
// set a default filesystem adatper if none has been configured |
164
|
|
|
if ($this->filesystemAdapter === null) { |
165
|
|
|
$this->filesystemAdapter = new FilesystemAdapter(); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Return's the multiple field delimiter character to use, default value is comma (,). |
171
|
|
|
* |
172
|
|
|
* @return string The multiple field delimiter character |
173
|
|
|
*/ |
174
|
|
|
public function getMultipleFieldDelimiter() |
175
|
|
|
{ |
176
|
|
|
return $this->getConfiguration()->getMultipleFieldDelimiter(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Return's the multiple value delimiter character to use, default value is comma (|). |
181
|
|
|
* |
182
|
|
|
* @return string The multiple value delimiter character |
183
|
|
|
*/ |
184
|
|
|
public function getMultipleValueDelimiter() |
185
|
|
|
{ |
186
|
|
|
return $this->getConfiguration()->getMultipleValueDelimiter(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Return's the delimiter character to use, default value is comma (,). |
191
|
|
|
* |
192
|
|
|
* @return string The delimiter character |
193
|
|
|
*/ |
194
|
|
|
public function getDelimiter() |
195
|
|
|
{ |
196
|
|
|
return $this->getConfiguration()->getDelimiter(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* The enclosure character to use, default value is double quotation ("). |
201
|
|
|
* |
202
|
|
|
* @return string The enclosure character |
203
|
|
|
*/ |
204
|
|
|
public function getEnclosure() |
205
|
|
|
{ |
206
|
|
|
return $this->getConfiguration()->getEnclosure(); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* The escape character to use, default value is backslash (\). |
211
|
|
|
* |
212
|
|
|
* @return string The escape character |
213
|
|
|
*/ |
214
|
|
|
public function getEscape() |
215
|
|
|
{ |
216
|
|
|
return $this->getConfiguration()->getEscape(); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* The file encoding of the CSV source file, default value is UTF-8. |
221
|
|
|
* |
222
|
|
|
* @return string The charset used by the CSV source file |
223
|
|
|
*/ |
224
|
|
|
public function getFromCharset() |
225
|
|
|
{ |
226
|
|
|
return $this->getConfiguration()->getFromCharset(); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* The file encoding of the CSV targetfile, default value is UTF-8. |
231
|
|
|
* |
232
|
|
|
* @return string The charset used by the CSV target file |
233
|
|
|
*/ |
234
|
|
|
public function getToCharset() |
235
|
|
|
{ |
236
|
|
|
return $this->getConfiguration()->getToCharset(); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* The file mode of the CSV target file, either one of write or append, default is write. |
241
|
|
|
* |
242
|
|
|
* @return string The file mode of the CSV target file |
243
|
|
|
*/ |
244
|
|
|
public function getFileMode() |
245
|
|
|
{ |
246
|
|
|
return $this->getConfiguration()->getFileMode(); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Queries whether or not strict mode is enabled or not, default is TRUE. |
251
|
|
|
* |
252
|
|
|
* @return boolean TRUE if strict mode is enabled, else FALSE |
253
|
|
|
*/ |
254
|
|
|
public function isStrictMode() |
255
|
|
|
{ |
256
|
|
|
return $this->getConfiguration()->isStrictMode(); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Return's the subject's source date format to use. |
261
|
|
|
* |
262
|
|
|
* @return string The source date format |
263
|
|
|
*/ |
264
|
|
|
public function getSourceDateFormat() |
265
|
|
|
{ |
266
|
|
|
return $this->getConfiguration()->getSourceDateFormat(); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Return's the source directory that has to be watched for new files. |
271
|
|
|
* |
272
|
|
|
* @return string The source directory |
273
|
|
|
*/ |
274
|
|
|
public function getSourceDir() |
275
|
|
|
{ |
276
|
|
|
return $this->getConfiguration()->getSourceDir(); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Return's the target directory with the files that has been imported. |
281
|
|
|
* |
282
|
|
|
* @return string The target directory |
283
|
|
|
*/ |
284
|
|
|
public function getTargetDir() |
285
|
|
|
{ |
286
|
|
|
return $this->getConfiguration()->getTargetDir(); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Queries whether or not debug mode is enabled or not, default is TRUE. |
291
|
|
|
* |
292
|
|
|
* @return boolean TRUE if debug mode is enabled, else FALSE |
293
|
|
|
*/ |
294
|
|
|
public function isDebugMode() |
295
|
|
|
{ |
296
|
|
|
return $this->getConfiguration()->isDebugMode(); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Return's the subject's unique DI identifier. |
301
|
|
|
* |
302
|
|
|
* @return string The subject's unique DI identifier |
303
|
|
|
*/ |
304
|
|
|
public function getId() |
305
|
|
|
{ |
306
|
|
|
return $this->id; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Set's the reference to the configuration instance. |
311
|
|
|
* |
312
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
313
|
|
|
* |
314
|
|
|
* @return void |
315
|
|
|
*/ |
316
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
317
|
|
|
{ |
318
|
|
|
$this->configuration = $configuration; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Return's the reference to the configuration instance. |
323
|
|
|
* |
324
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
325
|
|
|
*/ |
326
|
|
|
public function getConfiguration() |
327
|
|
|
{ |
328
|
|
|
return $this->configuration; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Set's the prefix for the import files. |
333
|
|
|
* |
334
|
|
|
* @param string $prefix The prefix |
335
|
|
|
* |
336
|
|
|
* @return void |
337
|
|
|
*/ |
338
|
|
|
public function setPrefix($prefix) |
339
|
|
|
{ |
340
|
|
|
$this->prefix = $prefix; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Return's the prefix for the import files. |
345
|
|
|
* |
346
|
|
|
* @return string The prefix |
347
|
|
|
*/ |
348
|
|
|
public function getPrefix() |
349
|
|
|
{ |
350
|
|
|
return $this->prefix; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Set's the suffix for the import files. |
355
|
|
|
* |
356
|
|
|
* @param string $suffix The suffix |
357
|
|
|
* |
358
|
|
|
* @return void |
359
|
|
|
*/ |
360
|
|
|
public function setSuffix($suffix) |
361
|
|
|
{ |
362
|
|
|
$this->suffix = $suffix; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Return's the suffix for the import files. |
367
|
|
|
* |
368
|
|
|
* @return string The suffix |
369
|
|
|
*/ |
370
|
|
|
public function getSuffix() |
371
|
|
|
{ |
372
|
|
|
return $this->suffix; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Return's the array with the subject's observers. |
377
|
|
|
* |
378
|
|
|
* @return array The subject's observers |
379
|
|
|
*/ |
380
|
|
|
public function getObservers() |
381
|
|
|
{ |
382
|
|
|
return $this->observers; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Return's the array with the subject's callbacks. |
387
|
|
|
* |
388
|
|
|
* @return array The subject's callbacks |
389
|
|
|
*/ |
390
|
|
|
public function getCallbacks() |
391
|
|
|
{ |
392
|
|
|
return $this->callbacks; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Return's the array with the subject's frontend input callbacks. |
397
|
|
|
* |
398
|
|
|
* @return array The subject's frontend input callbacks |
399
|
|
|
*/ |
400
|
|
|
public function getFrontendInputCallbacks() |
401
|
|
|
{ |
402
|
|
|
return $this->frontendInputCallbacks; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Set's the flag to signal that the an OK file is needed for the subject |
407
|
|
|
* to be processed. |
408
|
|
|
* |
409
|
|
|
* @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE |
410
|
|
|
* |
411
|
|
|
* @return void |
412
|
|
|
*/ |
413
|
|
|
public function setOkFileNeeded($okFileNeeded) |
414
|
|
|
{ |
415
|
|
|
$this->okFileNeeded = $okFileNeeded; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Queries whether or not that the subject needs an OK file to be processed. |
420
|
|
|
* |
421
|
|
|
* @return boolean TRUE if the subject needs an OK file, else FALSE |
422
|
|
|
*/ |
423
|
|
|
public function isOkFileNeeded() |
424
|
|
|
{ |
425
|
|
|
return $this->okFileNeeded; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Return's the import adapter configuration instance. |
430
|
|
|
* |
431
|
|
|
* @return \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface The import adapter configuration instance |
432
|
|
|
*/ |
433
|
|
|
public function getImportAdapter() |
434
|
|
|
{ |
435
|
|
|
return $this->importAdapter; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Return's the export adapter configuration instance. |
440
|
|
|
* |
441
|
|
|
* @return \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface The export adapter configuration instance |
442
|
|
|
*/ |
443
|
|
|
public function getExportAdapter() |
444
|
|
|
{ |
445
|
|
|
return $this->exportAdapter; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Return's the filesystem adapter configuration instance. |
450
|
|
|
* |
451
|
|
|
* @return \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface The filesystem adapter configuration instance |
452
|
|
|
*/ |
453
|
|
|
public function getFilesystemAdapter() |
454
|
|
|
{ |
455
|
|
|
return $this->filesystemAdapter; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* The array with the subject's custom header mappings. |
460
|
|
|
* |
461
|
|
|
* @return array The custom header mappings |
462
|
|
|
*/ |
463
|
|
|
public function getHeaderMappings() |
464
|
|
|
{ |
465
|
|
|
return $this->getConfiguration()->getHeaderMappings(); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* The array with the subject's custom image types. |
470
|
|
|
* |
471
|
|
|
* @return array The custom image types |
472
|
|
|
*/ |
473
|
|
|
public function getImageTypes() |
474
|
|
|
{ |
475
|
|
|
return $this->getConfiguration()->getImageTypes(); |
476
|
|
|
} |
477
|
|
|
} |
478
|
|
|
|