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