|
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
|
|
|
* Barcode |
|
16
|
|
|
* |
|
17
|
|
|
* @author Eymen Gunay <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class Barcode implements BarcodeInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public const TYPE_QR = 'PKBarcodeFormatQR'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
public const TYPE_PDF_417 = 'PKBarcodeFormatPDF417'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
public const TYPE_AZTEC = 'PKBarcodeFormatAztec'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Available starting with iOS 9. |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
public const TYPE_CODE_128 = 'PKBarcodeFormatCode128'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Barcode format. Must be one of the following values: |
|
44
|
|
|
* PKBarcodeFormatQR, PKBarcodeFormatPDF417, PKBarcodeFormatAztec. |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $format; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Message or payload to be displayed as a barcode. |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $message; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Text encoding that is used to convert the message |
|
57
|
|
|
* from the string representation to a data representation |
|
58
|
|
|
* to render the barcode. The value is typically iso-8859-1, |
|
59
|
|
|
* but you may use another encoding that is supported by |
|
60
|
|
|
* your barcode scanning infrastructure. |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $messageEncoding; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Text displayed near the barcode. For example, |
|
67
|
|
|
* a human-readable version of the barcode data |
|
68
|
|
|
* in case the barcode doesn’t scan. |
|
69
|
|
|
* @var string |
|
70
|
|
|
*/ |
|
71
|
|
|
protected $altText; |
|
72
|
|
|
|
|
73
|
8 |
|
public function __construct($format, $message, $messageEncoding = 'iso-8859-1') |
|
74
|
|
|
{ |
|
75
|
|
|
// Required |
|
76
|
8 |
|
$this->setMessage($message); |
|
77
|
8 |
|
$this->format = $format; |
|
78
|
8 |
|
$this->messageEncoding = $messageEncoding; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
5 |
|
public function toArray() |
|
82
|
|
|
{ |
|
83
|
5 |
|
$array = [ |
|
84
|
5 |
|
'format' => $this->getFormat(), |
|
85
|
5 |
|
'message' => $this->getMessage(), |
|
86
|
5 |
|
'messageEncoding' => $this->getMessageEncoding() |
|
87
|
5 |
|
]; |
|
88
|
|
|
|
|
89
|
5 |
|
if ($this->getAltText()) { |
|
90
|
2 |
|
$array['altText'] = $this->getAltText(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
5 |
|
return $array; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function setFormat($format) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$this->format = $format; |
|
102
|
|
|
|
|
103
|
1 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
7 |
|
public function getFormat() |
|
110
|
|
|
{ |
|
111
|
7 |
|
return $this->format; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* {@inheritdoc} |
|
116
|
|
|
*/ |
|
117
|
8 |
|
public function setMessage($message) |
|
118
|
|
|
{ |
|
119
|
8 |
|
$this->message = strval($message); |
|
120
|
|
|
|
|
121
|
8 |
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* {@inheritdoc} |
|
126
|
|
|
*/ |
|
127
|
7 |
|
public function getMessage() |
|
128
|
|
|
{ |
|
129
|
7 |
|
return $this->message; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* {@inheritdoc} |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function setMessageEncoding($messageEncoding) |
|
136
|
|
|
{ |
|
137
|
1 |
|
$this->messageEncoding = $messageEncoding; |
|
138
|
|
|
|
|
139
|
1 |
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritdoc} |
|
144
|
|
|
*/ |
|
145
|
5 |
|
public function getMessageEncoding() |
|
146
|
|
|
{ |
|
147
|
5 |
|
return $this->messageEncoding; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* {@inheritdoc} |
|
152
|
|
|
*/ |
|
153
|
2 |
|
public function setAltText($altText) |
|
154
|
|
|
{ |
|
155
|
2 |
|
$this->altText = strval($altText); |
|
156
|
|
|
|
|
157
|
2 |
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* {@inheritdoc} |
|
162
|
|
|
*/ |
|
163
|
5 |
|
public function getAltText() |
|
164
|
|
|
{ |
|
165
|
5 |
|
return $this->altText; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|