|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Configuration\Jms\Configuration\Subject\FilesystemAdapter |
|
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\Subject; |
|
22
|
|
|
|
|
23
|
|
|
use JMS\Serializer\Annotation\Type; |
|
24
|
|
|
use JMS\Serializer\Annotation\SerializedName; |
|
25
|
|
|
use JMS\Serializer\Annotation\PostDeserialize; |
|
26
|
|
|
use TechDivision\Import\Utils\BunchKeys; |
|
27
|
|
|
use TechDivision\Import\Utils\DependencyInjectionKeys; |
|
28
|
|
|
use TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The file resolver's configuration. |
|
32
|
|
|
* |
|
33
|
|
|
* @author Tim Wagner <[email protected]> |
|
34
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
36
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
|
37
|
|
|
* @link http://www.techdivision.com |
|
38
|
|
|
*/ |
|
39
|
|
|
class FileResolver implements FileResolverConfigurationInterface |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The file resolver's Symfony DI name. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
* @Type("string") |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $id = DependencyInjectionKeys::IMPORT_SUBJECT_FILE_RESOLVER_OK_FILE_AWARE; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The prefix/meta sequence of the import files. |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
* @Type("string") |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $prefix = '.*'; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The filename/meta sequence of the import files. |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
* @Type("string") |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $filename = '.*'; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* The counter/meta sequence of the import files. |
|
68
|
|
|
* |
|
69
|
|
|
* @var string |
|
70
|
|
|
* @Type("string") |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $counter = '\d+'; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* The file suffix for import files. |
|
76
|
|
|
* |
|
77
|
|
|
* @var string |
|
78
|
|
|
* @Type("string") |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $suffix = 'csv'; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* The file suffix for OK file. |
|
84
|
|
|
* |
|
85
|
|
|
* @var string |
|
86
|
|
|
* @Type("string") |
|
87
|
|
|
* @SerializedName("ok-file-suffix") |
|
88
|
|
|
*/ |
|
89
|
|
|
protected $okFileSuffix = 'ok'; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* The separator char for the elements of the file. |
|
93
|
|
|
* |
|
94
|
|
|
* @var string |
|
95
|
|
|
* @Type("string") |
|
96
|
|
|
* @SerializedName("element-separator") |
|
97
|
|
|
*/ |
|
98
|
|
|
protected $elementSeparator = '_'; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* The elements to create the regex pattern that is necessary decide a subject handles a file or not. |
|
102
|
|
|
* |
|
103
|
|
|
* @var string |
|
104
|
|
|
* @Type("array") |
|
105
|
|
|
* @SerializedName("pattern-elements") |
|
106
|
|
|
*/ |
|
107
|
|
|
protected $patternElements = null; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Initialize the instance with the file resolver's Symfony DI name. |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $id The Symfony DI name |
|
113
|
|
|
*/ |
|
114
|
|
|
public function __construct($id = DependencyInjectionKeys::IMPORT_SUBJECT_FILE_RESOLVER_OK_FILE_AWARE) |
|
115
|
|
|
{ |
|
116
|
|
|
// set the Symfony DI of the file resolver |
|
117
|
|
|
$this->id = $id; |
|
118
|
|
|
// initialize the pattern elements |
|
119
|
|
|
$this->patternElements = BunchKeys::getAllKeys(); |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Return's the file resolver's unique DI identifier. |
|
124
|
|
|
* |
|
125
|
|
|
* @return string The file resolvers's unique DI identifier |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getId() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->id; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Set's the prefix/meta sequence for the import files. |
|
134
|
|
|
* |
|
135
|
|
|
* @param string $prefix The prefix |
|
136
|
|
|
* |
|
137
|
|
|
* @return void |
|
138
|
|
|
*/ |
|
139
|
|
|
public function setPrefix($prefix) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->prefix = $prefix; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Query's whether or not a custom prefix has been configured for the |
|
146
|
|
|
* file resolver. |
|
147
|
|
|
* |
|
148
|
|
|
* @param string $defaultPrefix The default prefix to match against |
|
149
|
|
|
* |
|
150
|
|
|
* @return boolean TRUE if the file resolver has a custom prefix, else FALSE |
|
151
|
|
|
*/ |
|
152
|
|
|
public function hasPrefix($defaultPrefix = '.*') |
|
153
|
|
|
{ |
|
154
|
|
|
return strcmp($this->getPrefix(), $defaultPrefix) <> 0; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Return's the prefix/meta sequence for the import files. |
|
159
|
|
|
* |
|
160
|
|
|
* @return string The prefix |
|
161
|
|
|
*/ |
|
162
|
|
|
public function getPrefix() |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->prefix; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Return's the filename/meta sequence of the import files. |
|
169
|
|
|
* |
|
170
|
|
|
* @return string The suffix |
|
171
|
|
|
*/ |
|
172
|
|
|
public function getFilename() |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->filename; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Return's the counter/meta sequence of the import files. |
|
179
|
|
|
* |
|
180
|
|
|
* @return string The suffix |
|
181
|
|
|
*/ |
|
182
|
|
|
public function getCounter() |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->counter; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Return's the suffix for the import files. |
|
189
|
|
|
* |
|
190
|
|
|
* @return string The suffix |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getSuffix() |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->suffix; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Return's the suffix for the OK file. |
|
199
|
|
|
* |
|
200
|
|
|
* @return string The OK file suffix |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getOkFileSuffix() |
|
203
|
|
|
{ |
|
204
|
|
|
return $this->okFileSuffix; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Return's the delement separator char. |
|
209
|
|
|
* |
|
210
|
|
|
* @return string The element separator char |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getElementSeparator() |
|
213
|
|
|
{ |
|
214
|
|
|
return $this->elementSeparator; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Return's the elements the filenames consists of. |
|
219
|
|
|
* |
|
220
|
|
|
* @return array The array with the filename elements |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getPatternElements() |
|
223
|
|
|
{ |
|
224
|
|
|
return $this->patternElements; |
|
|
|
|
|
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Lifecycle callback that will be invoked after deserialization. |
|
229
|
|
|
* |
|
230
|
|
|
* @return void |
|
231
|
|
|
* @PostDeserialize |
|
232
|
|
|
*/ |
|
233
|
|
|
public function postDeserialize() |
|
234
|
|
|
{ |
|
235
|
|
|
|
|
236
|
|
|
// set the default pattern elements |
|
237
|
|
|
if ($this->patternElements === null) { |
|
238
|
|
|
$this->patternElements = BunchKeys::getAllKeys(); |
|
|
|
|
|
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..