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\PluginConfigurationInterface; |
28
|
|
|
use TechDivision\Import\Configuration\SubjectConfigurationInterface; |
29
|
|
|
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface; |
30
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\FileResolver; |
31
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter; |
32
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter; |
33
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\DateConverter; |
34
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\NumberConverter; |
35
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The subject configuration implementation. |
39
|
|
|
* |
40
|
|
|
* @author Tim Wagner <[email protected]> |
41
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
42
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
43
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
44
|
|
|
* @link http://www.techdivision.com |
45
|
|
|
*/ |
46
|
|
|
class Subject implements SubjectConfigurationInterface, ListenerAwareConfigurationInterface |
47
|
|
|
{ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The trait that provides parameter handling functionality. |
51
|
|
|
* |
52
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
53
|
|
|
*/ |
54
|
|
|
use ParamsTrait; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Trait that provides CSV configuration functionality. |
58
|
|
|
* |
59
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait |
60
|
|
|
*/ |
61
|
|
|
use ListenersTrait; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The subject's unique DI identifier. |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
* @Type("string") |
68
|
|
|
* @SerializedName("id") |
69
|
|
|
*/ |
70
|
|
|
protected $id; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* The subject's name. |
74
|
|
|
* |
75
|
|
|
* @var string |
76
|
|
|
* @Type("string") |
77
|
|
|
* @SerializedName("name") |
78
|
|
|
*/ |
79
|
|
|
protected $name; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* The array with the subject's observers. |
83
|
|
|
* |
84
|
|
|
* @var array |
85
|
|
|
* @Type("array") |
86
|
|
|
*/ |
87
|
|
|
protected $observers = array(); |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* The array with the subject's callbacks. |
91
|
|
|
* |
92
|
|
|
* @var array |
93
|
|
|
* @Type("array<string, array>") |
94
|
|
|
*/ |
95
|
|
|
protected $callbacks = array(); |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* The array with the subject's frontend input callbacks. |
99
|
|
|
* |
100
|
|
|
* @var array |
101
|
|
|
* @Type("array<string, array>") |
102
|
|
|
* @SerializedName("frontend-input-callbacks") |
103
|
|
|
*/ |
104
|
|
|
protected $frontendInputCallbacks = array(); |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* The flag to signal that the subjects needs a OK file to be processed or not. |
108
|
|
|
* |
109
|
|
|
* @var boolean |
110
|
|
|
* @Type("boolean") |
111
|
|
|
* @SerializedName("ok-file-needed") |
112
|
|
|
*/ |
113
|
|
|
protected $okFileNeeded = false; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
*The flag to signal that the subject has to create a .imported flagfile or not. |
117
|
|
|
* |
118
|
|
|
* @var boolean |
119
|
|
|
* @Type("boolean") |
120
|
|
|
* @SerializedName("create-imported-file") |
121
|
|
|
*/ |
122
|
|
|
protected $createImportedFile = true; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* The import adapter configuration instance. |
126
|
|
|
* |
127
|
|
|
* @var \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface |
128
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter") |
129
|
|
|
* @SerializedName("import-adapter") |
130
|
|
|
*/ |
131
|
|
|
protected $importAdapter; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* The export adapter configuration instance. |
135
|
|
|
* |
136
|
|
|
* @var \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface |
137
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter") |
138
|
|
|
* @SerializedName("export-adapter") |
139
|
|
|
*/ |
140
|
|
|
protected $exportAdapter; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* The filesystem adapter configuration instance. |
144
|
|
|
* |
145
|
|
|
* @var \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface |
146
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter") |
147
|
|
|
* @SerializedName("filesystem-adapter") |
148
|
|
|
*/ |
149
|
|
|
protected $filesystemAdapter; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* The file resolver configuration instance. |
153
|
|
|
* |
154
|
|
|
* @var \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface |
155
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FileResolver") |
156
|
|
|
* @SerializedName("file-resolver") |
157
|
|
|
*/ |
158
|
|
|
protected $fileResolver; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* The number converter configuration instance. |
162
|
|
|
* |
163
|
|
|
* @var \TechDivision\Import\Configuration\Subject\NumberConverterConfigurationInterface |
164
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\NumberConverter") |
165
|
|
|
* @SerializedName("number-converter") |
166
|
|
|
*/ |
167
|
|
|
protected $numberConverter; |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* The date converter configuration instance. |
171
|
|
|
* |
172
|
|
|
* @var \TechDivision\Import\Configuration\Subject\DateConverterConfigurationInterface |
173
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\DateConverter") |
174
|
|
|
* @SerializedName("date-converter") |
175
|
|
|
*/ |
176
|
|
|
protected $dateConverter; |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* The source directory that has to be watched for new files. |
180
|
|
|
* |
181
|
|
|
* @var string |
182
|
|
|
* @Type("string") |
183
|
|
|
* @SerializedName("source-dir") |
184
|
|
|
*/ |
185
|
|
|
protected $sourceDir; |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* The target directory with the files that has been imported. |
189
|
|
|
* |
190
|
|
|
* @var string |
191
|
|
|
* @Type("string") |
192
|
|
|
* @SerializedName("target-dir") |
193
|
|
|
*/ |
194
|
|
|
protected $targetDir; |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* A reference to the parent configuration instance. |
198
|
|
|
* |
199
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
200
|
|
|
*/ |
201
|
|
|
protected $configuration; |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* The configuration of the parent plugin. |
205
|
|
|
* |
206
|
|
|
* @var \TechDivision\Import\Configuration\PluginConfigurationInterface |
207
|
|
|
*/ |
208
|
|
|
protected $pluginConfiguration; |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Lifecycle callback that will be invoked after deserialization. |
212
|
|
|
* |
213
|
|
|
* @return void |
214
|
|
|
* @PostDeserialize |
215
|
|
|
*/ |
216
|
|
|
public function postDeserialize() |
217
|
|
|
{ |
218
|
|
|
|
219
|
|
|
// set a default import adatper if none has been configured |
220
|
|
|
if ($this->importAdapter === null) { |
221
|
|
|
$this->importAdapter = new ImportAdapter(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// set a default export adatper if none has been configured |
225
|
|
|
if ($this->exportAdapter === null) { |
226
|
|
|
$this->exportAdapter = new ExportAdapter(); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
// set a default filesystem adatper if none has been configured |
230
|
|
|
if ($this->filesystemAdapter === null) { |
231
|
|
|
$this->filesystemAdapter = new FilesystemAdapter(); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
// set a default file resolver if none has been configured |
235
|
|
|
if ($this->fileResolver === null) { |
236
|
|
|
$this->fileResolver = new FileResolver(); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
// set a default number converter if none has been configured |
240
|
|
|
if ($this->numberConverter === null) { |
241
|
|
|
$this->numberConverter = new NumberConverter(); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
// set a default date converter if none has been configured |
245
|
|
|
if ($this->dateConverter === null) { |
246
|
|
|
$this->dateConverter = new DateConverter(); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Return's the multiple field delimiter character to use, default value is comma (,). |
252
|
|
|
* |
253
|
|
|
* @return string The multiple field delimiter character |
254
|
|
|
*/ |
255
|
|
|
public function getMultipleFieldDelimiter() |
256
|
|
|
{ |
257
|
|
|
return $this->getConfiguration()->getMultipleFieldDelimiter(); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Return's the multiple value delimiter character to use, default value is comma (|). |
262
|
|
|
* |
263
|
|
|
* @return string The multiple value delimiter character |
264
|
|
|
*/ |
265
|
|
|
public function getMultipleValueDelimiter() |
266
|
|
|
{ |
267
|
|
|
return $this->getConfiguration()->getMultipleValueDelimiter(); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Return's the delimiter character to use, default value is comma (,). |
272
|
|
|
* |
273
|
|
|
* @return string The delimiter character |
274
|
|
|
*/ |
275
|
|
|
public function getDelimiter() |
276
|
|
|
{ |
277
|
|
|
return $this->getConfiguration()->getDelimiter(); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* The enclosure character to use, default value is double quotation ("). |
282
|
|
|
* |
283
|
|
|
* @return string The enclosure character |
284
|
|
|
*/ |
285
|
|
|
public function getEnclosure() |
286
|
|
|
{ |
287
|
|
|
return $this->getConfiguration()->getEnclosure(); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* The escape character to use, default value is backslash (\). |
292
|
|
|
* |
293
|
|
|
* @return string The escape character |
294
|
|
|
*/ |
295
|
|
|
public function getEscape() |
296
|
|
|
{ |
297
|
|
|
return $this->getConfiguration()->getEscape(); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* The file encoding of the CSV source file, default value is UTF-8. |
302
|
|
|
* |
303
|
|
|
* @return string The charset used by the CSV source file |
304
|
|
|
*/ |
305
|
|
|
public function getFromCharset() |
306
|
|
|
{ |
307
|
|
|
return $this->getConfiguration()->getFromCharset(); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* The file encoding of the CSV targetfile, default value is UTF-8. |
312
|
|
|
* |
313
|
|
|
* @return string The charset used by the CSV target file |
314
|
|
|
*/ |
315
|
|
|
public function getToCharset() |
316
|
|
|
{ |
317
|
|
|
return $this->getConfiguration()->getToCharset(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* The file mode of the CSV target file, either one of write or append, default is write. |
322
|
|
|
* |
323
|
|
|
* @return string The file mode of the CSV target file |
324
|
|
|
*/ |
325
|
|
|
public function getFileMode() |
326
|
|
|
{ |
327
|
|
|
return $this->getConfiguration()->getFileMode(); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Queries whether or not strict mode is enabled or not, default is TRUE. |
332
|
|
|
* |
333
|
|
|
* @return boolean TRUE if strict mode is enabled, else FALSE |
334
|
|
|
*/ |
335
|
|
|
public function isStrictMode() |
336
|
|
|
{ |
337
|
|
|
return $this->getConfiguration()->isStrictMode(); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Return's the subject's source date format to use. |
342
|
|
|
* |
343
|
|
|
* @return string The source date format |
344
|
|
|
*/ |
345
|
|
|
public function getSourceDateFormat() |
346
|
|
|
{ |
347
|
|
|
return $this->getDateConverter()->getSourceDateFormat(); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Return's the source directory that has to be watched for new files. |
352
|
|
|
* |
353
|
|
|
* @return string The source directory |
354
|
|
|
*/ |
355
|
|
|
public function getSourceDir() |
356
|
|
|
{ |
357
|
|
|
return $this->sourceDir ? $this->sourceDir : $this->getConfiguration()->getSourceDir(); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Return's the target directory with the files that has been imported. |
362
|
|
|
* |
363
|
|
|
* @return string The target directory |
364
|
|
|
*/ |
365
|
|
|
public function getTargetDir() |
366
|
|
|
{ |
367
|
|
|
return $this->targetDir ? $this->targetDir : $this->getConfiguration()->getTargetDir(); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Queries whether or not debug mode is enabled or not, default is TRUE. |
372
|
|
|
* |
373
|
|
|
* @return boolean TRUE if debug mode is enabled, else FALSE |
374
|
|
|
*/ |
375
|
|
|
public function isDebugMode() |
376
|
|
|
{ |
377
|
|
|
return $this->getConfiguration()->isDebugMode(); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Return's the subject's unique DI identifier. |
382
|
|
|
* |
383
|
|
|
* @return string The subject's unique DI identifier |
384
|
|
|
*/ |
385
|
|
|
public function getId() |
386
|
|
|
{ |
387
|
|
|
return $this->id; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Return's the subject's name or the ID, if the name is NOT set. |
392
|
|
|
* |
393
|
|
|
* @return string The subject's name |
394
|
|
|
* @see \TechDivision\Import\Configuration\SubjectConfigurationInterface::getId() |
395
|
|
|
*/ |
396
|
|
|
public function getName() |
397
|
|
|
{ |
398
|
|
|
return $this->name ? $this->name : $this->getId(); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Set's the reference to the configuration instance. |
403
|
|
|
* |
404
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
405
|
|
|
* |
406
|
|
|
* @return void |
407
|
|
|
*/ |
408
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
409
|
|
|
{ |
410
|
|
|
$this->configuration = $configuration; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Return's the reference to the configuration instance. |
415
|
|
|
* |
416
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
417
|
|
|
*/ |
418
|
|
|
public function getConfiguration() |
419
|
|
|
{ |
420
|
|
|
return $this->configuration; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Set's the reference to the parent plugin configuration instance. |
425
|
|
|
* |
426
|
|
|
* @param \TechDivision\Import\Configuration\PluginConfigurationInterface $pluginConfiguration The parent plugin configuration instance |
427
|
|
|
* |
428
|
|
|
* @return void |
429
|
|
|
*/ |
430
|
|
|
public function setPluginConfiguration(PluginConfigurationInterface $pluginConfiguration) |
431
|
|
|
{ |
432
|
|
|
$this->pluginConfiguration = $pluginConfiguration; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Return's the reference to the parent plugin configuration instance. |
437
|
|
|
* |
438
|
|
|
* @return \TechDivision\Import\Configuration\PluginConfigurationInterface The parent plugin configuration instance |
439
|
|
|
*/ |
440
|
|
|
public function getPluginConfiguration() |
441
|
|
|
{ |
442
|
|
|
return $this->pluginConfiguration; |
|
|
|
|
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Return's the prefix for the import files. |
447
|
|
|
* |
448
|
|
|
* @return string The prefix |
449
|
|
|
*/ |
450
|
|
|
public function getPrefix() |
451
|
|
|
{ |
452
|
|
|
return $this->getFileResolver()->getPrefix(); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Return's the array with the subject's observers. |
457
|
|
|
* |
458
|
|
|
* @return array The subject's observers |
459
|
|
|
*/ |
460
|
|
|
public function getObservers() |
461
|
|
|
{ |
462
|
|
|
return $this->observers; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* Return's the array with the subject's callbacks. |
467
|
|
|
* |
468
|
|
|
* @return array The subject's callbacks |
469
|
|
|
*/ |
470
|
|
|
public function getCallbacks() |
471
|
|
|
{ |
472
|
|
|
return $this->callbacks; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Return's the array with the subject's frontend input callbacks. |
477
|
|
|
* |
478
|
|
|
* @return array The subject's frontend input callbacks |
479
|
|
|
*/ |
480
|
|
|
public function getFrontendInputCallbacks() |
481
|
|
|
{ |
482
|
|
|
return $this->frontendInputCallbacks; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Set's the flag to signal that the an OK file is needed for the subject |
487
|
|
|
* to be processed. |
488
|
|
|
* |
489
|
|
|
* @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE |
490
|
|
|
* |
491
|
|
|
* @return void |
492
|
|
|
*/ |
493
|
|
|
public function setOkFileNeeded($okFileNeeded) |
494
|
|
|
{ |
495
|
|
|
$this->okFileNeeded = $okFileNeeded; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Queries whether or not that the subject needs an OK file to be processed. |
500
|
|
|
* |
501
|
|
|
* @return boolean TRUE if the subject needs an OK file, else FALSE |
502
|
|
|
*/ |
503
|
|
|
public function isOkFileNeeded() |
504
|
|
|
{ |
505
|
|
|
return $this->okFileNeeded; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* Queries whether or not the subject should create a .imported flagfile |
510
|
|
|
* |
511
|
|
|
* @return boolean TRUE if subject has to create the .imported flagfile, else FALSE |
512
|
|
|
*/ |
513
|
|
|
public function isCreatingImportedFile() |
514
|
|
|
{ |
515
|
|
|
return $this->createImportedFile; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Return's the import adapter configuration instance. |
520
|
|
|
* |
521
|
|
|
* @return \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface The import adapter configuration instance |
522
|
|
|
*/ |
523
|
|
|
public function getImportAdapter() |
524
|
|
|
{ |
525
|
|
|
return $this->importAdapter; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Return's the export adapter configuration instance. |
530
|
|
|
* |
531
|
|
|
* @return \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface The export adapter configuration instance |
532
|
|
|
*/ |
533
|
|
|
public function getExportAdapter() |
534
|
|
|
{ |
535
|
|
|
return $this->exportAdapter; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* Return's the filesystem adapter configuration instance. |
540
|
|
|
* |
541
|
|
|
* @return \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface The filesystem adapter configuration instance |
542
|
|
|
*/ |
543
|
|
|
public function getFilesystemAdapter() |
544
|
|
|
{ |
545
|
|
|
return $this->filesystemAdapter; |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Return's the file resolver configuration instance. |
550
|
|
|
* |
551
|
|
|
* @return \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface The file resolver configuration instance |
552
|
|
|
*/ |
553
|
|
|
public function getFileResolver() |
554
|
|
|
{ |
555
|
|
|
return $this->fileResolver; |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
/** |
559
|
|
|
* Return's the number converter configuration instance. |
560
|
|
|
* |
561
|
|
|
* @return \TechDivision\Import\Configuration\Subject\NumberConverterConfigurationInterface The number converter configuration instance |
562
|
|
|
*/ |
563
|
|
|
public function getNumberConverter() |
564
|
|
|
{ |
565
|
|
|
return $this->numberConverter; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Return's the date converter configuration instance. |
570
|
|
|
* |
571
|
|
|
* @return \TechDivision\Import\Configuration\Subject\DateConverterConfigurationInterface The date converter configuration instance |
572
|
|
|
*/ |
573
|
|
|
public function getDateConverter() |
574
|
|
|
{ |
575
|
|
|
return $this->dateConverter; |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* The array with the subject's custom header mappings. |
580
|
|
|
* |
581
|
|
|
* @return array The custom header mappings |
582
|
|
|
*/ |
583
|
|
|
public function getHeaderMappings() |
584
|
|
|
{ |
585
|
|
|
return $this->getConfiguration()->getHeaderMappings(); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* The array with the subject's custom image types. |
590
|
|
|
* |
591
|
|
|
* @return array The custom image types |
592
|
|
|
*/ |
593
|
|
|
public function getImageTypes() |
594
|
|
|
{ |
595
|
|
|
return $this->getConfiguration()->getImageTypes(); |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
/** |
599
|
|
|
* Return's the execution context configuration for the actualy plugin configuration. |
600
|
|
|
* |
601
|
|
|
* @return \TechDivision\Import\ExecutionContextInterface The execution context to use |
602
|
|
|
*/ |
603
|
|
|
public function getExecutionContext() |
604
|
|
|
{ |
605
|
|
|
return $this->getPluginConfiguration()->getExecutionContext(); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* Load the default values from the configuration. |
610
|
|
|
* |
611
|
|
|
* @return array The array with the default values |
612
|
|
|
*/ |
613
|
|
|
public function getDefaultValues() |
614
|
|
|
{ |
615
|
|
|
return $this->getConfiguration()->getDefaultValues(); |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* Return's the full opration name, which consists of the Magento edition, the entity type code and the operation name. |
620
|
|
|
* |
621
|
|
|
* @param string $separator The separator used to seperate the elements |
622
|
|
|
* |
623
|
|
|
* @return string The full operation name |
624
|
|
|
*/ |
625
|
|
|
public function getFullOperationName($separator = '/') |
|
|
|
|
626
|
|
|
{ |
627
|
|
|
return $this->getPluginConfiguration()->getFullOperationName(); |
628
|
|
|
} |
629
|
|
|
} |
630
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.