Completed
Push — master ( e0920c...db9f02 )
by Tim
12s
created

Subject::getHeaderMappings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
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
     * A reference to the parent configuration instance.
94
     *
95
     * @var \TechDivision\Import\ConfigurationInterface
96
     */
97
    protected $configuration;
98
99
    /**
100
     * The flag to signal that the subjects needs a OK file to be processed or not.
101
     *
102
     * @var boolean
103
     * @Type("boolean")
104
     * @SerializedName("ok-file-needed")
105
     */
106
    protected $okFileNeeded = false;
107
108
    /**
109
     * The import adapter configuration instance.
110
     *
111
     * @var \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface
112
     * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter")
113
     * @SerializedName("import-adapter")
114
     */
115
    protected $importAdapter;
116
117
    /**
118
     * The export adapter configuration instance.
119
     *
120
     * @var \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface
121
     * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter")
122
     * @SerializedName("export-adapter")
123
     */
124
    protected $exportAdapter;
125
126
    /**
127
     * The filesystem adapter configuration instance.
128
     *
129
     * @var \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface
130
     * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter")
131
     * @SerializedName("filesystem-adapter")
132
     */
133
    protected $filesystemAdapter;
134
135
    /**
136
     * The array with the custom header mappings.
137
     *
138
     * @var array
139
     * @Type("array")
140
     * @SerializedName("header-mappings")
141
     */
142
    protected $headerMappings = array();
143
144
    /**
145
     * The array with the custom image types.
146
     *
147
     * @var array
148
     * @Type("array")
149
     * @SerializedName("image-types")
150
     */
151
    protected $imageTypes = array();
152
153
    /**
154
     * Lifecycle callback that will be invoked after deserialization.
155
     *
156
     * @return void
157
     * @PostDeserialize
158
     */
159
    public function postDeserialize()
160
    {
161
162
        // set a default import adatper if none has been configured
163
        if ($this->importAdapter === null) {
164
            $this->importAdapter = new ImportAdapter();
165
        }
166
167
        // set a default export adatper if none has been configured
168
        if ($this->exportAdapter === null) {
169
            $this->exportAdapter = new ExportAdapter();
170
        }
171
172
        // set a default filesystem adatper if none has been configured
173
        if ($this->filesystemAdapter === null) {
174
            $this->filesystemAdapter = new FilesystemAdapter();
175
        }
176
    }
177
178
    /**
179
     * Return's the multiple field delimiter character to use, default value is comma (,).
180
     *
181
     * @return string The multiple field delimiter character
182
     */
183
    public function getMultipleFieldDelimiter()
184
    {
185
        return $this->getConfiguration()->getMultipleFieldDelimiter();
186
    }
187
188
    /**
189
     * Return's the multiple value delimiter character to use, default value is comma (|).
190
     *
191
     * @return string The multiple value delimiter character
192
     */
193
    public function getMultipleValueDelimiter()
194
    {
195
        return $this->getConfiguration()->getMultipleValueDelimiter();
196
    }
197
198
    /**
199
     * Return's the delimiter character to use, default value is comma (,).
200
     *
201
     * @return string The delimiter character
202
     */
203
    public function getDelimiter()
204
    {
205
        return $this->getConfiguration()->getDelimiter();
206
    }
207
208
    /**
209
     * The enclosure character to use, default value is double quotation (").
210
     *
211
     * @return string The enclosure character
212
     */
213
    public function getEnclosure()
214
    {
215
        return $this->getConfiguration()->getEnclosure();
216
    }
217
218
    /**
219
     * The escape character to use, default value is backslash (\).
220
     *
221
     * @return string The escape character
222
     */
223
    public function getEscape()
224
    {
225
        return $this->getConfiguration()->getEscape();
226
    }
227
228
    /**
229
     * The file encoding of the CSV source file, default value is UTF-8.
230
     *
231
     * @return string The charset used by the CSV source file
232
     */
233
    public function getFromCharset()
234
    {
235
        return $this->getConfiguration()->getFromCharset();
236
    }
237
238
    /**
239
     * The file encoding of the CSV targetfile, default value is UTF-8.
240
     *
241
     * @return string The charset used by the CSV target file
242
     */
243
    public function getToCharset()
244
    {
245
        return $this->getConfiguration()->getToCharset();
246
    }
247
248
    /**
249
     * The file mode of the CSV target file, either one of write or append, default is write.
250
     *
251
     * @return string The file mode of the CSV target file
252
     */
253
    public function getFileMode()
254
    {
255
        return $this->getConfiguration()->getFileMode();
256
    }
257
258
    /**
259
     * Queries whether or not strict mode is enabled or not, default is TRUE.
260
     *
261
     * @return boolean TRUE if strict mode is enabled, else FALSE
262
     */
263
    public function isStrictMode()
264
    {
265
        return $this->getConfiguration()->isStrictMode();
266
    }
267
268
    /**
269
     * Return's the subject's source date format to use.
270
     *
271
     * @return string The source date format
272
     */
273
    public function getSourceDateFormat()
274
    {
275
        return $this->getConfiguration()->getSourceDateFormat();
276
    }
277
278
    /**
279
     * Return's the source directory that has to be watched for new files.
280
     *
281
     * @return string The source directory
282
     */
283
    public function getSourceDir()
284
    {
285
        return $this->getConfiguration()->getSourceDir();
286
    }
287
288
    /**
289
     * Return's the target directory with the files that has been imported.
290
     *
291
     * @return string The target directory
292
     */
293
    public function getTargetDir()
294
    {
295
        return $this->getConfiguration()->getTargetDir();
296
    }
297
298
    /**
299
     * Queries whether or not debug mode is enabled or not, default is TRUE.
300
     *
301
     * @return boolean TRUE if debug mode is enabled, else FALSE
302
     */
303
    public function isDebugMode()
304
    {
305
        return $this->getConfiguration()->isDebugMode();
306
    }
307
308
    /**
309
     * Return's the subject's unique DI identifier.
310
     *
311
     * @return string The subject's unique DI identifier
312
     */
313
    public function getId()
314
    {
315
        return $this->id;
316
    }
317
318
    /**
319
     * Set's the reference to the configuration instance.
320
     *
321
     * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance
322
     *
323
     * @return void
324
     */
325
    public function setConfiguration(ConfigurationInterface $configuration)
326
    {
327
        $this->configuration = $configuration;
328
    }
329
330
    /**
331
     * Return's the reference to the configuration instance.
332
     *
333
     * @return \TechDivision\Import\ConfigurationInterface The configuration instance
334
     */
335
    public function getConfiguration()
336
    {
337
        return $this->configuration;
338
    }
339
340
    /**
341
     * Set's the prefix for the import files.
342
     *
343
     * @param string $prefix The prefix
344
     *
345
     * @return void
346
     */
347
    public function setPrefix($prefix)
348
    {
349
        $this->prefix = $prefix;
350
    }
351
352
    /**
353
     * Return's the prefix for the import files.
354
     *
355
     * @return string The prefix
356
     */
357
    public function getPrefix()
358
    {
359
        return $this->prefix;
360
    }
361
362
    /**
363
     * Set's the suffix for the import files.
364
     *
365
     * @param string $suffix The suffix
366
     *
367
     * @return void
368
     */
369
    public function setSuffix($suffix)
370
    {
371
        $this->suffix = $suffix;
372
    }
373
374
    /**
375
     * Return's the suffix for the import files.
376
     *
377
     * @return string The suffix
378
     */
379
    public function getSuffix()
380
    {
381
        return $this->suffix;
382
    }
383
384
    /**
385
     * Return's the array with the subject's observers.
386
     *
387
     * @return array The subject's observers
388
     */
389
    public function getObservers()
390
    {
391
        return $this->observers;
392
    }
393
394
    /**
395
     * Return's the array with the subject's callbacks.
396
     *
397
     * @return array The subject's callbacks
398
     */
399
    public function getCallbacks()
400
    {
401
        return $this->callbacks;
402
    }
403
404
    /**
405
     * Set's the flag to signal that the an OK file is needed for the subject
406
     * to be processed.
407
     *
408
     * @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE
409
     *
410
     * @return void
411
     */
412
    public function setOkFileNeeded($okFileNeeded)
413
    {
414
        $this->okFileNeeded = $okFileNeeded;
415
    }
416
417
    /**
418
     * Queries whether or not that the subject needs an OK file to be processed.
419
     *
420
     * @return boolean TRUE if the subject needs an OK file, else FALSE
421
     */
422
    public function isOkFileNeeded()
423
    {
424
        return $this->okFileNeeded;
425
    }
426
427
    /**
428
     * Return's the import adapter configuration instance.
429
     *
430
     * @return \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface The import adapter configuration instance
431
     */
432
    public function getImportAdapter()
433
    {
434
        return $this->importAdapter;
435
    }
436
437
    /**
438
     * Return's the export adapter configuration instance.
439
     *
440
     * @return \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface The export adapter configuration instance
441
     */
442
    public function getExportAdapter()
443
    {
444
        return $this->exportAdapter;
445
    }
446
447
    /**
448
     * Return's the filesystem adapter configuration instance.
449
     *
450
     * @return \TechDivision\Import\Configuration\Subject\FilesystemAdapterConfigurationInterface The filesystem adapter configuration instance
451
     */
452
    public function getFilesystemAdapter()
453
    {
454
        return $this->filesystemAdapter;
455
    }
456
457
    /**
458
     * The array with the subject's custom header mappings.
459
     *
460
     * @return array The custom header mappings
461
     */
462
    public function getHeaderMappings()
463
    {
464
465
        // initialize the array for the custom header mappings
466
        $headerMappings = array();
467
468
        // try to load the configured header mappings
469
        if ($headerMappingsAvailable = reset($this->headerMappings)) {
470
            $headerMappings = $headerMappingsAvailable;
471
        }
472
473
        // return the custom header mappings
474
        return $headerMappings;
475
    }
476
477
    /**
478
     * The array with the subject's custom image types.
479
     *
480
     * @return array The custom image types
481
     */
482
    public function getImageTypes()
483
    {
484
485
        // initialize the array for the custom image types
486
        $imageTypes = array();
487
488
        // try to load the configured image types
489
        if ($imageTypesAvailable = reset($this->imageTypes)) {
490
            $imageTypes = $imageTypesAvailable;
491
        }
492
493
        // return the custom image types
494
        return $imageTypes;
495
    }
496
}
497