|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Cli\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-cli-simple |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli\Configuration; |
|
22
|
|
|
|
|
23
|
|
|
use JMS\Serializer\Annotation\Type; |
|
24
|
|
|
use JMS\Serializer\Annotation\SerializedName; |
|
25
|
|
|
use TechDivision\Import\ConfigurationInterface; |
|
26
|
|
|
use TechDivision\Import\Configuration\SubjectInterface; |
|
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-cli-simple |
|
35
|
|
|
* @link http://www.techdivision.com |
|
36
|
|
|
*/ |
|
37
|
|
|
class Subject implements SubjectInterface |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The subject's class name. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
* @Type("string") |
|
45
|
|
|
* @SerializedName("class-name") |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $className; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The subject's processor type to use. |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
* @Type("string") |
|
54
|
|
|
* @SerializedName("processor-factory") |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $processorFactory; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The subject's utility class with the SQL statements to use. |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
* @Type("string") |
|
63
|
|
|
* @SerializedName("utility-class-name") |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $utilityClassName; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* The file prefix for import files. |
|
69
|
|
|
* |
|
70
|
|
|
* @var string |
|
71
|
|
|
* @Type("string") |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $prefix = 'magento-import'; |
|
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
|
|
|
* The array with the subject's params. |
|
93
|
|
|
* |
|
94
|
|
|
* @var array |
|
95
|
|
|
* @Type("array") |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $params = array(); |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* A reference to the parent configuration instance. |
|
101
|
|
|
* |
|
102
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
|
103
|
|
|
*/ |
|
104
|
|
|
protected $configuration; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Return's the multiple field delimiter character to use, default value is comma (,). |
|
108
|
|
|
* |
|
109
|
|
|
* @return string The multiple field delimiter character |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getMultipleFieldDelimiter() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->getConfiguration()->getMultipleFieldDelimiter(); |
|
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 class name. |
|
228
|
|
|
* |
|
229
|
|
|
* @return string The subject's class name |
|
230
|
|
|
*/ |
|
231
|
|
|
public function getClassName() |
|
232
|
|
|
{ |
|
233
|
|
|
return $this->className; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Return's the subject's processor factory type to use. |
|
238
|
|
|
* |
|
239
|
|
|
* @return string The subject's processor factory type |
|
240
|
|
|
*/ |
|
241
|
|
|
public function getProcessorFactory() |
|
242
|
|
|
{ |
|
243
|
|
|
return $this->processorFactory; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Return's the utility class with the SQL statements to use. |
|
248
|
|
|
* |
|
249
|
|
|
* @return string The utility class name |
|
250
|
|
|
*/ |
|
251
|
|
|
public function getUtilityClassName() |
|
252
|
|
|
{ |
|
253
|
|
|
return $this->utilityClassName; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Return's the array with the params. |
|
258
|
|
|
* |
|
259
|
|
|
* @return array The params |
|
260
|
|
|
*/ |
|
261
|
|
|
public function getParams() |
|
262
|
|
|
{ |
|
263
|
|
|
if (!$params = reset($this->params)) { |
|
264
|
|
|
$params = array(); |
|
265
|
|
|
} |
|
266
|
|
|
return $params; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Query whether or not the param with the passed name exists. |
|
271
|
|
|
* |
|
272
|
|
|
* @param string $name The name of the param to be queried |
|
273
|
|
|
* |
|
274
|
|
|
* @return boolean TRUE if the requested param exists, else FALSE |
|
275
|
|
|
*/ |
|
276
|
|
|
public function hasParam($name) |
|
277
|
|
|
{ |
|
278
|
|
|
return array_key_exists($name, $this->getParams()); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* Return's the param with the passed name. |
|
283
|
|
|
* |
|
284
|
|
|
* @param string $name The name of the param to return |
|
285
|
|
|
* @param mixed $defaultValue The default value if the param doesn't exists |
|
286
|
|
|
* |
|
287
|
|
|
* @return string The requested param |
|
288
|
|
|
* @throws \Exception Is thrown, if the requested param is not available |
|
289
|
|
|
*/ |
|
290
|
|
|
public function getParam($name, $defaultValue = null) |
|
291
|
|
|
{ |
|
292
|
|
|
|
|
293
|
|
|
// query whether or not, the param is set |
|
294
|
|
|
if (array_key_exists($name, $params = $this->getParams())) { |
|
295
|
|
|
return $params[$name]; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
// if not, query we query if a default value has been passed |
|
299
|
|
|
if ($defaultValue != null) { |
|
300
|
|
|
return $defaultValue; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
// throw an exception if neither the param exists or a default value has been passed |
|
304
|
|
|
throw new \Exception(sprintf('Requested param %s not available', $name)); |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Set's the reference to the configuration instance. |
|
309
|
|
|
* |
|
310
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
|
311
|
|
|
* |
|
312
|
|
|
* @return void |
|
313
|
|
|
*/ |
|
314
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
|
315
|
|
|
{ |
|
316
|
|
|
$this->configuration = $configuration; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* Return's the reference to the configuration instance. |
|
321
|
|
|
* |
|
322
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
|
323
|
|
|
*/ |
|
324
|
|
|
public function getConfiguration() |
|
325
|
|
|
{ |
|
326
|
|
|
return $this->configuration; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Set's the prefix for the import files. |
|
331
|
|
|
* |
|
332
|
|
|
* @param string $prefix The prefix |
|
333
|
|
|
* |
|
334
|
|
|
* @return void |
|
335
|
|
|
*/ |
|
336
|
|
|
public function setPrefix($prefix) |
|
337
|
|
|
{ |
|
338
|
|
|
$this->prefix = $prefix; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Return's the prefix for the import files. |
|
343
|
|
|
* |
|
344
|
|
|
* @return string The prefix |
|
345
|
|
|
*/ |
|
346
|
|
|
public function getPrefix() |
|
347
|
|
|
{ |
|
348
|
|
|
return $this->prefix; |
|
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
|
|
|
|