1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of JSON definition |
4
|
|
|
*/ |
5
|
|
|
namespace Graviton\GeneratorBundle\Definition\Schema; |
6
|
|
|
|
7
|
|
|
use Graviton\GeneratorBundle\Definition\Schema\XDynamicKey; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* JSON definition "target.fields" |
11
|
|
|
* |
12
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
13
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
14
|
|
|
* @link http://swisscom.ch |
15
|
|
|
*/ |
16
|
|
|
class Field |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $name; |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $type; |
26
|
|
|
/** |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $length; |
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
private $minLength; |
34
|
|
|
/** |
35
|
|
|
* @var int |
36
|
|
|
*/ |
37
|
|
|
private $maxLength; |
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $title; |
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $description; |
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $exposeAs; |
50
|
|
|
/** |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
private $readOnly = false; |
54
|
|
|
/** |
55
|
|
|
* @var bool |
56
|
|
|
*/ |
57
|
|
|
private $recordOriginException = false; |
58
|
|
|
/** |
59
|
|
|
* @var bool |
60
|
|
|
*/ |
61
|
|
|
private $required = false; |
62
|
|
|
/** |
63
|
|
|
* @var integer |
64
|
|
|
*/ |
65
|
|
|
private $searchable = 0; |
66
|
|
|
/** |
67
|
|
|
* @var bool |
68
|
|
|
*/ |
69
|
|
|
private $translatable = false; |
70
|
|
|
/** |
71
|
|
|
* @var Constraint[] |
72
|
|
|
*/ |
73
|
|
|
private $constraints = []; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
private $collection = []; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var XDynamicKey |
82
|
|
|
*/ |
83
|
|
|
private $xDynamicKey; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
30 |
|
public function getName() |
89
|
|
|
{ |
90
|
30 |
|
return $this->name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $name Field name |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
16 |
|
public function setName($name) |
98
|
|
|
{ |
99
|
16 |
|
$this->name = $name; |
100
|
16 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
80 |
|
public function getType() |
107
|
|
|
{ |
108
|
80 |
|
return $this->type; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $type Field type |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
58 |
|
public function setType($type) |
116
|
|
|
{ |
117
|
58 |
|
$this->type = $type; |
118
|
58 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return int |
123
|
|
|
*/ |
124
|
16 |
|
public function getLength() |
125
|
|
|
{ |
126
|
16 |
|
return $this->length; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param int $length Field length |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
4 |
|
public function setLength($length) |
134
|
|
|
{ |
135
|
4 |
|
$this->length = $length; |
136
|
4 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return int min length |
141
|
|
|
*/ |
142
|
16 |
|
public function getMinLength() |
143
|
|
|
{ |
144
|
16 |
|
return $this->minLength; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param int $minLength min length |
149
|
|
|
* @return this |
|
|
|
|
150
|
|
|
*/ |
151
|
|
|
public function setMinLength($minLength) |
152
|
|
|
{ |
153
|
|
|
$this->minLength = $minLength; |
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return int max length |
159
|
|
|
*/ |
160
|
16 |
|
public function getMaxLength() |
161
|
|
|
{ |
162
|
16 |
|
return $this->maxLength; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param int $maxLength max length |
167
|
|
|
* @return this |
|
|
|
|
168
|
|
|
*/ |
169
|
|
|
public function setMaxLength($maxLength) |
170
|
|
|
{ |
171
|
|
|
$this->maxLength = $maxLength; |
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
22 |
|
public function getTitle() |
179
|
|
|
{ |
180
|
22 |
|
return $this->title; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param string $title Field title |
185
|
|
|
* @return $this |
186
|
|
|
*/ |
187
|
6 |
|
public function setTitle($title) |
188
|
|
|
{ |
189
|
6 |
|
$this->title = $title; |
190
|
6 |
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
22 |
|
public function getDescription() |
197
|
|
|
{ |
198
|
22 |
|
return $this->description; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param string $description Field description |
203
|
|
|
* @return $this |
204
|
|
|
*/ |
205
|
12 |
|
public function setDescription($description) |
206
|
|
|
{ |
207
|
12 |
|
$this->description = $description; |
208
|
12 |
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
18 |
|
public function getExposeAs() |
215
|
|
|
{ |
216
|
18 |
|
return $this->exposeAs; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param string $exposeAs Expose field as ... |
221
|
|
|
* @return $this |
222
|
|
|
*/ |
223
|
10 |
|
public function setExposeAs($exposeAs) |
224
|
|
|
{ |
225
|
10 |
|
$this->exposeAs = $exposeAs; |
226
|
10 |
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return bool |
231
|
|
|
*/ |
232
|
18 |
|
public function getReadOnly() |
|
|
|
|
233
|
|
|
{ |
234
|
18 |
|
return $this->readOnly; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param bool $readOnly Is field readonly |
239
|
|
|
* @return $this |
240
|
|
|
*/ |
241
|
6 |
|
public function setReadOnly($readOnly) |
242
|
|
|
{ |
243
|
6 |
|
$this->readOnly = $readOnly; |
244
|
6 |
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* get RecordOriginException |
249
|
|
|
* |
250
|
|
|
* @return boolean RecordOriginException |
251
|
|
|
*/ |
252
|
16 |
|
public function isRecordOriginException() |
253
|
|
|
{ |
254
|
16 |
|
return $this->recordOriginException; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* set RecordOriginException |
259
|
|
|
* |
260
|
|
|
* @param boolean $recordOriginException recordOriginException |
261
|
|
|
* |
262
|
|
|
* @return void |
263
|
|
|
*/ |
264
|
|
|
public function setRecordOriginException($recordOriginException) |
265
|
|
|
{ |
266
|
|
|
$this->recordOriginException = $recordOriginException; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @return bool |
271
|
|
|
*/ |
272
|
20 |
|
public function getRequired() |
|
|
|
|
273
|
|
|
{ |
274
|
20 |
|
return $this->required; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param bool $required Is field required |
279
|
|
|
* @return $this |
280
|
|
|
*/ |
281
|
10 |
|
public function setRequired($required) |
282
|
|
|
{ |
283
|
10 |
|
$this->required = $required; |
284
|
10 |
|
return $this; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return bool |
289
|
|
|
*/ |
290
|
16 |
|
public function getTranslatable() |
|
|
|
|
291
|
|
|
{ |
292
|
16 |
|
return $this->translatable; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @param bool $translatable Is field translatable |
297
|
|
|
* @return $this |
298
|
|
|
*/ |
299
|
4 |
|
public function setTranslatable($translatable) |
300
|
|
|
{ |
301
|
4 |
|
$this->translatable = $translatable; |
302
|
4 |
|
return $this; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return Constraint[] |
307
|
|
|
*/ |
308
|
18 |
|
public function getConstraints() |
309
|
|
|
{ |
310
|
18 |
|
return $this->constraints; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @param Constraint[] $constraints Field constraints |
315
|
|
|
* @return $this |
316
|
|
|
*/ |
317
|
4 |
|
public function setConstraints(array $constraints) |
318
|
|
|
{ |
319
|
4 |
|
$this->constraints = $constraints; |
320
|
4 |
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return array |
325
|
|
|
*/ |
326
|
16 |
|
public function getCollection() |
327
|
|
|
{ |
328
|
16 |
|
return $this->collection; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param array $collection Field |
333
|
|
|
* @return $this |
334
|
|
|
*/ |
335
|
4 |
|
public function setCollection(array $collection) |
336
|
|
|
{ |
337
|
4 |
|
$this->collection = $collection; |
338
|
4 |
|
return $this; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return XDynamicKey |
343
|
|
|
*/ |
344
|
16 |
|
public function getXDynamicKey() |
345
|
|
|
{ |
346
|
16 |
|
return $this->xDynamicKey; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* @param XDynamicKey $xDynamicKey x-dynamic-key field value |
351
|
|
|
* @return $this |
352
|
|
|
*/ |
353
|
2 |
|
public function setXDynamicKey(XDynamicKey $xDynamicKey) |
354
|
|
|
{ |
355
|
2 |
|
$this->xDynamicKey = $xDynamicKey; |
356
|
2 |
|
return $this; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @return integer |
361
|
|
|
*/ |
362
|
18 |
|
public function getSearchable() |
363
|
|
|
{ |
364
|
18 |
|
return (int) $this->searchable; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param integer $searchable searchable flag |
369
|
|
|
* |
370
|
|
|
* @return void |
371
|
|
|
*/ |
372
|
|
|
public function setSearchable($searchable) |
373
|
|
|
{ |
374
|
|
|
$this->searchable = (int) $searchable; |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.