Completed
Push — master ( 3271a2...ea0247 )
by Tim
12s
created

Subject::postDeserialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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