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
|
|
|
* Location |
16
|
|
|
* |
17
|
|
|
* @author Eymen Gunay <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Location implements LocationInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Altitude, in meters, of the location. |
23
|
|
|
* @var float |
24
|
|
|
*/ |
25
|
|
|
protected $altitude; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Latitude, in degrees, of the location. |
29
|
|
|
* @var float |
30
|
|
|
*/ |
31
|
|
|
protected $latitude; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Longitude, in degrees, of the location. |
35
|
|
|
* @var float |
36
|
|
|
*/ |
37
|
|
|
protected $longitude; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Text displayed on the lock screen when the pass is currently relevant. |
41
|
|
|
* For example, a description of the nearby location such as |
42
|
|
|
* “Store nearby on 1st and Main.” |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $relevantText; |
46
|
|
|
|
47
|
4 |
|
public function __construct($latitude, $longitude) |
48
|
|
|
{ |
49
|
|
|
// Required |
50
|
4 |
|
$this->setLatitude($latitude); |
51
|
4 |
|
$this->setLongitude($longitude); |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
public function toArray() |
55
|
|
|
{ |
56
|
3 |
|
$array = [ |
57
|
3 |
|
'latitude' => $this->getLatitude(), |
58
|
3 |
|
'longitude' => $this->getLongitude() |
59
|
3 |
|
]; |
60
|
|
|
|
61
|
3 |
|
if ($altitude = $this->getAltitude()) { |
62
|
1 |
|
$array['altitude'] = $altitude; |
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
if ($relevantText = $this->getRelevantText()) { |
66
|
1 |
|
$array['relevantText'] = $relevantText; |
67
|
|
|
} |
68
|
|
|
|
69
|
3 |
|
return $array; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
2 |
|
public function setAltitude($altitude) |
76
|
|
|
{ |
77
|
2 |
|
$this->altitude = $altitude; |
78
|
|
|
|
79
|
2 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
4 |
|
public function getAltitude() |
86
|
|
|
{ |
87
|
4 |
|
return is_numeric($this->altitude) ? floatval($this->altitude) : $this->altitude; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
4 |
|
public function setLatitude($latitude) |
94
|
|
|
{ |
95
|
4 |
|
$this->latitude = $latitude; |
96
|
|
|
|
97
|
4 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
4 |
|
public function getLatitude() |
104
|
|
|
{ |
105
|
4 |
|
return is_numeric($this->latitude) ? floatval($this->latitude) : $this->latitude; |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
4 |
|
public function setLongitude($longitude) |
112
|
|
|
{ |
113
|
4 |
|
$this->longitude = $longitude; |
114
|
|
|
|
115
|
4 |
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
4 |
|
public function getLongitude() |
122
|
|
|
{ |
123
|
4 |
|
return is_numeric($this->longitude) ? floatval($this->longitude) : $this->longitude; |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
1 |
|
public function setRelevantText($relevantText) |
130
|
|
|
{ |
131
|
1 |
|
$this->relevantText = $relevantText; |
132
|
|
|
|
133
|
1 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
3 |
|
public function getRelevantText() |
140
|
|
|
{ |
141
|
3 |
|
return $this->relevantText; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|