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