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 TechDivision\Import\ConfigurationInterface; |
26
|
|
|
use TechDivision\Import\Configuration\SubjectConfigurationInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The subject configuration implementation. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
35
|
|
|
* @link http://www.techdivision.com |
36
|
|
|
*/ |
37
|
|
|
class Subject implements SubjectConfigurationInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The trait that provides parameter handling functionality. |
42
|
|
|
* |
43
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
44
|
|
|
*/ |
45
|
|
|
use ParamsTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The subject's unique DI identifier. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
* @Type("string") |
52
|
|
|
* @SerializedName("id") |
53
|
|
|
*/ |
54
|
|
|
protected $id; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The file prefix for import files. |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
* @Type("string") |
61
|
|
|
*/ |
62
|
|
|
protected $prefix = 'magento-import'; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The array with the subject's observers. |
66
|
|
|
* |
67
|
|
|
* @var array |
68
|
|
|
* @Type("array") |
69
|
|
|
*/ |
70
|
|
|
protected $observers = array(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* The array with the subject's callbacks. |
74
|
|
|
* |
75
|
|
|
* @var array |
76
|
|
|
* @Type("array<string, array>") |
77
|
|
|
*/ |
78
|
|
|
protected $callbacks = array(); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* A reference to the parent configuration instance. |
82
|
|
|
* |
83
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
84
|
|
|
*/ |
85
|
|
|
protected $configuration; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* The flag to signal that the subjects needs a OK file to be processed or not. |
89
|
|
|
* |
90
|
|
|
* @var boolean |
91
|
|
|
* @Type("boolean") |
92
|
|
|
* @SerializedName("ok-file-needed") |
93
|
|
|
*/ |
94
|
|
|
protected $okFileNeeded = false; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Return's the multiple field delimiter character to use, default value is comma (,). |
98
|
|
|
* |
99
|
|
|
* @return string The multiple field delimiter character |
100
|
|
|
*/ |
101
|
|
|
public function getMultipleFieldDelimiter() |
102
|
|
|
{ |
103
|
|
|
return $this->getConfiguration()->getMultipleFieldDelimiter(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Return's the multiple value delimiter character to use, default value is comma (|). |
108
|
|
|
* |
109
|
|
|
* @return string The multiple value delimiter character |
110
|
|
|
*/ |
111
|
|
|
public function getMultipleValueDelimiter() |
112
|
|
|
{ |
113
|
|
|
return $this->getConfiguration()->getMultipleValueDelimiter(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Return's the delimiter character to use, default value is comma (,). |
118
|
|
|
* |
119
|
|
|
* @return string The delimiter character |
120
|
|
|
*/ |
121
|
|
|
public function getDelimiter() |
122
|
|
|
{ |
123
|
|
|
return $this->getConfiguration()->getDelimiter(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* The enclosure character to use, default value is double quotation ("). |
128
|
|
|
* |
129
|
|
|
* @return string The enclosure character |
130
|
|
|
*/ |
131
|
|
|
public function getEnclosure() |
132
|
|
|
{ |
133
|
|
|
return $this->getConfiguration()->getEnclosure(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* The escape character to use, default value is backslash (\). |
138
|
|
|
* |
139
|
|
|
* @return string The escape character |
140
|
|
|
*/ |
141
|
|
|
public function getEscape() |
142
|
|
|
{ |
143
|
|
|
return $this->getConfiguration()->getEscape(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* The file encoding of the CSV source file, default value is UTF-8. |
148
|
|
|
* |
149
|
|
|
* @return string The charset used by the CSV source file |
150
|
|
|
*/ |
151
|
|
|
public function getFromCharset() |
152
|
|
|
{ |
153
|
|
|
return $this->getConfiguration()->getFromCharset(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* The file encoding of the CSV targetfile, default value is UTF-8. |
158
|
|
|
* |
159
|
|
|
* @return string The charset used by the CSV target file |
160
|
|
|
*/ |
161
|
|
|
public function getToCharset() |
162
|
|
|
{ |
163
|
|
|
return $this->getConfiguration()->getToCharset(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* The file mode of the CSV target file, either one of write or append, default is write. |
168
|
|
|
* |
169
|
|
|
* @return string The file mode of the CSV target file |
170
|
|
|
*/ |
171
|
|
|
public function getFileMode() |
172
|
|
|
{ |
173
|
|
|
return $this->getConfiguration()->getFileMode(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Queries whether or not strict mode is enabled or not, default is TRUE. |
178
|
|
|
* |
179
|
|
|
* @return boolean TRUE if strict mode is enabled, else FALSE |
180
|
|
|
*/ |
181
|
|
|
public function isStrictMode() |
182
|
|
|
{ |
183
|
|
|
return $this->getConfiguration()->isStrictMode(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Return's the subject's source date format to use. |
188
|
|
|
* |
189
|
|
|
* @return string The source date format |
190
|
|
|
*/ |
191
|
|
|
public function getSourceDateFormat() |
192
|
|
|
{ |
193
|
|
|
return $this->getConfiguration()->getSourceDateFormat(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Return's the source directory that has to be watched for new files. |
198
|
|
|
* |
199
|
|
|
* @return string The source directory |
200
|
|
|
*/ |
201
|
|
|
public function getSourceDir() |
202
|
|
|
{ |
203
|
|
|
return $this->getConfiguration()->getSourceDir(); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Return's the target directory with the files that has been imported. |
208
|
|
|
* |
209
|
|
|
* @return string The target directory |
210
|
|
|
*/ |
211
|
|
|
public function getTargetDir() |
212
|
|
|
{ |
213
|
|
|
return $this->getConfiguration()->getTargetDir(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Queries whether or not debug mode is enabled or not, default is TRUE. |
218
|
|
|
* |
219
|
|
|
* @return boolean TRUE if debug mode is enabled, else FALSE |
220
|
|
|
*/ |
221
|
|
|
public function isDebugMode() |
222
|
|
|
{ |
223
|
|
|
return $this->getConfiguration()->isDebugMode(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Return's the subject's unique DI identifier. |
228
|
|
|
* |
229
|
|
|
* @return string The subject's unique DI identifier |
230
|
|
|
*/ |
231
|
|
|
public function getId() |
232
|
|
|
{ |
233
|
|
|
return $this->id; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Set's the reference to the configuration instance. |
238
|
|
|
* |
239
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
240
|
|
|
* |
241
|
|
|
* @return void |
242
|
|
|
*/ |
243
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
244
|
|
|
{ |
245
|
|
|
$this->configuration = $configuration; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Return's the reference to the configuration instance. |
250
|
|
|
* |
251
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
252
|
|
|
*/ |
253
|
|
|
public function getConfiguration() |
254
|
|
|
{ |
255
|
|
|
return $this->configuration; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Set's the prefix for the import files. |
260
|
|
|
* |
261
|
|
|
* @param string $prefix The prefix |
262
|
|
|
* |
263
|
|
|
* @return void |
264
|
|
|
*/ |
265
|
|
|
public function setPrefix($prefix) |
266
|
|
|
{ |
267
|
|
|
$this->prefix = $prefix; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Return's the prefix for the import files. |
272
|
|
|
* |
273
|
|
|
* @return string The prefix |
274
|
|
|
*/ |
275
|
|
|
public function getPrefix() |
276
|
|
|
{ |
277
|
|
|
return $this->prefix; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Return's the array with the subject's observers. |
282
|
|
|
* |
283
|
|
|
* @return array The subject's observers |
284
|
|
|
*/ |
285
|
|
|
public function getObservers() |
286
|
|
|
{ |
287
|
|
|
return $this->observers; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Return's the array with the subject's callbacks. |
292
|
|
|
* |
293
|
|
|
* @return array The subject's callbacks |
294
|
|
|
*/ |
295
|
|
|
public function getCallbacks() |
296
|
|
|
{ |
297
|
|
|
return $this->callbacks; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Set's the flag to signal that the an OK file is needed for the subject |
302
|
|
|
* to be processed. |
303
|
|
|
* |
304
|
|
|
* @param boolean $okFileNeeded TRUE if the subject needs an OK file, else FALSE |
305
|
|
|
* |
306
|
|
|
* @return void |
307
|
|
|
*/ |
308
|
|
|
public function setOkFileNeeded($okFileNeeded) |
309
|
|
|
{ |
310
|
|
|
$this->okFileNeeded = $okFileNeeded; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Queries whether or not that the subject needs an OK file to be processed. |
315
|
|
|
* |
316
|
|
|
* @return boolean TRUE if the subject needs an OK file, else FALSE |
317
|
|
|
*/ |
318
|
|
|
public function isOkFileNeeded() |
319
|
|
|
{ |
320
|
|
|
return $this->okFileNeeded; |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|