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
|
|
|
* Return's the prefix/meta sequence for the import files. |
146
|
|
|
* |
147
|
|
|
* @return string The prefix |
148
|
|
|
*/ |
149
|
|
|
public function getPrefix() |
150
|
|
|
{ |
151
|
|
|
return $this->prefix; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Return's the filename/meta sequence of the import files. |
156
|
|
|
* |
157
|
|
|
* @return string The suffix |
158
|
|
|
*/ |
159
|
|
|
public function getFilename() |
160
|
|
|
{ |
161
|
|
|
return $this->filename; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Return's the counter/meta sequence of the import files. |
166
|
|
|
* |
167
|
|
|
* @return string The suffix |
168
|
|
|
*/ |
169
|
|
|
public function getCounter() |
170
|
|
|
{ |
171
|
|
|
return $this->counter; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Return's the suffix for the import files. |
176
|
|
|
* |
177
|
|
|
* @return string The suffix |
178
|
|
|
*/ |
179
|
|
|
public function getSuffix() |
180
|
|
|
{ |
181
|
|
|
return $this->suffix; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Return's the suffix for the OK file. |
186
|
|
|
* |
187
|
|
|
* @return string The OK file suffix |
188
|
|
|
*/ |
189
|
|
|
public function getOkFileSuffix() |
190
|
|
|
{ |
191
|
|
|
return $this->okFileSuffix; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Return's the delement separator char. |
196
|
|
|
* |
197
|
|
|
* @return string The element separator char |
198
|
|
|
*/ |
199
|
|
|
public function getElementSeparator() |
200
|
|
|
{ |
201
|
|
|
return $this->elementSeparator; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Return's the elements the filenames consists of. |
206
|
|
|
* |
207
|
|
|
* @return array The array with the filename elements |
208
|
|
|
*/ |
209
|
|
|
public function getPatternElements() |
210
|
|
|
{ |
211
|
|
|
return $this->patternElements; |
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Lifecycle callback that will be invoked after deserialization. |
216
|
|
|
* |
217
|
|
|
* @return void |
218
|
|
|
* @PostDeserialize |
219
|
|
|
*/ |
220
|
|
|
public function postDeserialize() |
221
|
|
|
{ |
222
|
|
|
|
223
|
|
|
// set the default pattern elements |
224
|
|
|
if ($this->patternElements === null) { |
225
|
|
|
$this->patternElements = BunchKeys::getAllKeys(); |
|
|
|
|
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
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..