|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Passbook package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eymen Gunay <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Passbook\Pass; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Field |
|
16
|
|
|
* @author Eymen Gunay <[email protected]> |
|
17
|
|
|
* @phpcs:disable Generic.NamingConventions.UpperCaseConstantName |
|
18
|
|
|
*/ |
|
19
|
|
|
class Field implements FieldInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public const ALIGN_LEFT = 'PKTextAlignmentLeft'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
public const ALIGN_CENTER = 'PKTextAlignmentCenter'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
public const ALIGN_RIGHT = 'PKTextAlignmentRight'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
public const ALIGN_NATURAL = 'PKTextAlignmentNatural'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @deprecated please use ::DATA_DETECTOR_TYPE_PHONE_NUMBER instead. |
|
43
|
|
|
*/ |
|
44
|
|
|
public const PKDataDetectorTypePhoneNumber = 'PKDataDetectorTypePhoneNumber'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @deprecated please use ::DATA_DETECTOR_TYPE_LINK instead. |
|
48
|
|
|
*/ |
|
49
|
|
|
public const PKDataDetectorTypeLink = 'PKDataDetectorTypeLink'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @deprecated please use ::DATA_DETECTOR_TYPE_ADDRESS instead. |
|
53
|
|
|
*/ |
|
54
|
|
|
public const PKDataDetectorTypeAddress = 'PKDataDetectorTypeAddress'; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @deprecated please use ::DATA_DETECTOR_TYPE_CALENDAR_EVENT instead. |
|
58
|
|
|
*/ |
|
59
|
|
|
public const PKDataDetectorTypeCalendarEvent = 'PKDataDetectorTypeCalendarEvent'; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var string |
|
63
|
|
|
*/ |
|
64
|
|
|
public const DATA_DETECTOR_TYPE_PHONE_NUMBER = 'PKDataDetectorTypePhoneNumber'; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var string |
|
68
|
|
|
*/ |
|
69
|
|
|
public const DATA_DETECTOR_TYPE_LINK = 'PKDataDetectorTypeLink'; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var string |
|
73
|
|
|
*/ |
|
74
|
|
|
public const DATA_DETECTOR_TYPE_ADDRESS = 'PKDataDetectorTypeAddress'; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @var string |
|
78
|
|
|
*/ |
|
79
|
|
|
public const DATA_DETECTOR_TYPE_CALENDAR_EVENT = 'PKDataDetectorTypeCalendarEvent'; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Format string for the alert text that is displayed when the pass is updated. |
|
83
|
|
|
* The format string may contain the escape %@, which is replaced with the |
|
84
|
|
|
* field’s new value. For example, “Gate changed to %@.” |
|
85
|
|
|
* @var string |
|
86
|
|
|
*/ |
|
87
|
|
|
protected $changeMessage; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* The key must be unique within the scope of the entire pass. |
|
91
|
|
|
* For example, “departure-gate”. |
|
92
|
|
|
* @var string |
|
93
|
|
|
*/ |
|
94
|
|
|
protected $key; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Label text for the field. |
|
98
|
|
|
* @var string |
|
99
|
|
|
*/ |
|
100
|
|
|
protected $label; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Alignment for the field’s contents. Must be one of the following values: |
|
104
|
|
|
* PKTextAlignmentLeft, PKTextAlignmentCenter, PKTextAlignmentRight, PKTextAlignmentNatural |
|
105
|
|
|
* The default value is natural alignment, |
|
106
|
|
|
* which aligns the text appropriately based on its script direction. |
|
107
|
|
|
* This key is not allowed for primary fields. |
|
108
|
|
|
* @var string |
|
109
|
|
|
*/ |
|
110
|
|
|
protected $textAlignment; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Value of the field. For example, 42. |
|
114
|
|
|
* @var mixed ISO 8601 date as a string, or number |
|
115
|
|
|
*/ |
|
116
|
|
|
protected $value; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Array of strings |
|
120
|
|
|
* The default value is all data detectors. Provide an empty array to use no data detectors. |
|
121
|
|
|
* Data detectors are applied only to back fields. |
|
122
|
|
|
* @link https://developer.apple.com/library/ios/documentation/userexperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html#//apple_ref/doc/uid/TP40012026-CH4-SW1 |
|
123
|
|
|
* @var array |
|
124
|
|
|
*/ |
|
125
|
|
|
protected $dataDetectorTypes; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Localizable string, ISO 8601 date as a string, or number |
|
129
|
|
|
* @var string |
|
130
|
|
|
*/ |
|
131
|
|
|
protected $attributedValue; |
|
132
|
|
|
|
|
133
|
9 |
|
public function __construct($key, $value) |
|
134
|
|
|
{ |
|
135
|
|
|
// Required |
|
136
|
9 |
|
$this->setKey($key); |
|
137
|
9 |
|
$this->setValue($value); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
8 |
|
public function toArray() |
|
141
|
|
|
{ |
|
142
|
8 |
|
$array = [ |
|
143
|
8 |
|
'key' => $this->getKey(), |
|
144
|
8 |
|
'value' => $this->getValue() |
|
145
|
8 |
|
]; |
|
146
|
|
|
|
|
147
|
8 |
|
if ($this->getChangeMessage()) { |
|
148
|
1 |
|
$array['changeMessage'] = $this->getChangeMessage(); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
8 |
|
if ($this->getLabel()) { |
|
152
|
4 |
|
$array['label'] = $this->getLabel(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
8 |
|
if ($this->getTextAlignment()) { |
|
156
|
1 |
|
$array['textAlignment'] = $this->getTextAlignment(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
8 |
|
if ($this->getDataDetectorTypes()) { |
|
160
|
|
|
$array['dataDetectorTypes'] = $this->getDataDetectorTypes(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
8 |
|
if ($this->getAttributedValue()) { |
|
164
|
|
|
$array['attributedValue'] = $this->getAttributedValue(); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
8 |
|
return $array; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* {@inheritdoc} |
|
172
|
|
|
*/ |
|
173
|
1 |
|
public function setChangeMessage($changeMessage) |
|
174
|
|
|
{ |
|
175
|
1 |
|
$this->changeMessage = $changeMessage; |
|
176
|
|
|
|
|
177
|
1 |
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* {@inheritdoc} |
|
182
|
|
|
*/ |
|
183
|
8 |
|
public function getChangeMessage() |
|
184
|
|
|
{ |
|
185
|
8 |
|
return $this->changeMessage; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* {@inheritdoc} |
|
190
|
|
|
*/ |
|
191
|
9 |
|
public function setKey($key) |
|
192
|
|
|
{ |
|
193
|
9 |
|
$this->key = $key; |
|
194
|
|
|
|
|
195
|
9 |
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* {@inheritdoc} |
|
200
|
|
|
*/ |
|
201
|
8 |
|
public function getKey() |
|
202
|
|
|
{ |
|
203
|
8 |
|
return $this->key; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* {@inheritdoc} |
|
208
|
|
|
*/ |
|
209
|
4 |
|
public function setLabel($label) |
|
210
|
|
|
{ |
|
211
|
4 |
|
$this->label = $label; |
|
212
|
|
|
|
|
213
|
4 |
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* {@inheritdoc} |
|
218
|
|
|
*/ |
|
219
|
8 |
|
public function getLabel() |
|
220
|
|
|
{ |
|
221
|
8 |
|
return $this->label; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* {@inheritdoc} |
|
226
|
|
|
*/ |
|
227
|
1 |
|
public function setTextAlignment($textAlignment) |
|
228
|
|
|
{ |
|
229
|
1 |
|
$this->textAlignment = $textAlignment; |
|
230
|
|
|
|
|
231
|
1 |
|
return $this; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* {@inheritdoc} |
|
236
|
|
|
*/ |
|
237
|
8 |
|
public function getTextAlignment() |
|
238
|
|
|
{ |
|
239
|
8 |
|
return $this->textAlignment; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* {@inheritdoc} |
|
244
|
|
|
*/ |
|
245
|
9 |
|
public function setValue($value) |
|
246
|
|
|
{ |
|
247
|
9 |
|
$this->value = $value; |
|
248
|
|
|
|
|
249
|
9 |
|
return $this; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* {@inheritdoc} |
|
254
|
|
|
*/ |
|
255
|
9 |
|
public function getValue() |
|
256
|
|
|
{ |
|
257
|
9 |
|
return $this->value; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* {@inheritdoc} |
|
262
|
|
|
*/ |
|
263
|
|
|
public function setAttributedValue($attributedValue) |
|
264
|
|
|
{ |
|
265
|
|
|
$this->attributedValue = $attributedValue; |
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* {@inheritdoc} |
|
271
|
|
|
*/ |
|
272
|
8 |
|
public function getAttributedValue() |
|
273
|
|
|
{ |
|
274
|
8 |
|
return $this->attributedValue; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* {@inheritdoc} |
|
279
|
|
|
*/ |
|
280
|
|
|
public function setDataDetectorTypes(array $dataDetectorTypes) |
|
281
|
|
|
{ |
|
282
|
|
|
$this->dataDetectorTypes = $dataDetectorTypes; |
|
283
|
|
|
return $this; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* {@inheritdoc} |
|
288
|
|
|
*/ |
|
289
|
8 |
|
public function getDataDetectorTypes() |
|
290
|
|
|
{ |
|
291
|
8 |
|
return $this->dataDetectorTypes; |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
|