|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Geotools library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Antoine Corcy <[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 League\Geotools\Batch; |
|
13
|
|
|
|
|
14
|
|
|
use Geocoder\Location; |
|
15
|
|
|
use Geocoder\Model\Address; |
|
16
|
|
|
use Geocoder\Model\Coordinates; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* BatchGeocoded class |
|
20
|
|
|
* |
|
21
|
|
|
* @author Antoine Corcy <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class BatchGeocoded |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* The name of the provider. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $providerName; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The query. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $query; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The exception message. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $exception; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The Location object. |
|
48
|
|
|
* |
|
49
|
|
|
* @var Location |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $address; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the name of the provider. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string The name of the provider. |
|
57
|
|
|
*/ |
|
58
|
10 |
|
public function getProviderName() |
|
59
|
|
|
{ |
|
60
|
10 |
|
return $this->providerName; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set the name of the provider. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $providerName The name of the provider. |
|
67
|
|
|
*/ |
|
68
|
16 |
|
public function setProviderName($providerName) |
|
69
|
|
|
{ |
|
70
|
16 |
|
$this->providerName = $providerName; |
|
71
|
16 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get the query. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string The query. |
|
77
|
|
|
*/ |
|
78
|
10 |
|
public function getQuery() |
|
79
|
|
|
{ |
|
80
|
10 |
|
return $this->query; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Set the query. |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $query The query. |
|
87
|
|
|
*/ |
|
88
|
16 |
|
public function setQuery($query) |
|
89
|
|
|
{ |
|
90
|
16 |
|
$this->query = $query; |
|
91
|
16 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the exception message. |
|
95
|
|
|
* |
|
96
|
|
|
* @return string The exception message. |
|
97
|
|
|
*/ |
|
98
|
2 |
|
public function getExceptionMessage() |
|
99
|
|
|
{ |
|
100
|
2 |
|
return $this->exception; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Set the exception message. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $exception The exception message. |
|
107
|
|
|
*/ |
|
108
|
16 |
|
public function setExceptionMessage($exception) |
|
109
|
|
|
{ |
|
110
|
16 |
|
$this->exception = $exception; |
|
111
|
16 |
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get the address |
|
115
|
|
|
* |
|
116
|
|
|
* @return Location |
|
117
|
|
|
*/ |
|
118
|
2 |
|
public function getAddress() |
|
119
|
|
|
{ |
|
120
|
2 |
|
return $this->address; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Set the address |
|
125
|
|
|
* |
|
126
|
|
|
* @param Location $address |
|
127
|
|
|
*/ |
|
128
|
10 |
|
public function setAddress($address) |
|
129
|
|
|
{ |
|
130
|
10 |
|
$this->address = $address; |
|
131
|
10 |
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Returns an array of coordinates (latitude, longitude). |
|
135
|
|
|
* |
|
136
|
|
|
* @return Coordinates|null |
|
137
|
|
|
*/ |
|
138
|
18 |
|
public function getCoordinates() |
|
139
|
|
|
{ |
|
140
|
18 |
|
if (null === $this->address) { |
|
141
|
8 |
|
return null; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
10 |
|
return $this->address->getCoordinates(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Returns the latitude value. |
|
149
|
|
|
* |
|
150
|
|
|
* @return double |
|
151
|
|
|
*/ |
|
152
|
18 |
|
public function getLatitude() |
|
153
|
|
|
{ |
|
154
|
18 |
|
if (null === $coordinates = $this->getCoordinates()) { |
|
155
|
10 |
|
return null; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
8 |
|
return $coordinates->getLatitude(); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Returns the longitude value. |
|
163
|
|
|
* |
|
164
|
|
|
* @return double |
|
165
|
|
|
*/ |
|
166
|
18 |
|
public function getLongitude() |
|
167
|
|
|
{ |
|
168
|
18 |
|
if (null === $coordinates = $this->getCoordinates()) { |
|
169
|
10 |
|
return null; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
8 |
|
return $coordinates->getLongitude(); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Create an instance from an array, used from cache libraries. |
|
177
|
|
|
* |
|
178
|
|
|
* @param array $data |
|
179
|
|
|
*/ |
|
180
|
2 |
|
public function fromArray(array $data = []) |
|
181
|
|
|
{ |
|
182
|
2 |
|
if (isset($data['providerName'])) { |
|
183
|
1 |
|
$this->providerName = $data['providerName']; |
|
184
|
|
|
} |
|
185
|
2 |
|
if (isset($data['query'])) { |
|
186
|
1 |
|
$this->query = $data['query']; |
|
187
|
|
|
} |
|
188
|
2 |
|
if (isset($data['exception'])) { |
|
189
|
1 |
|
$this->exception = $data['exception']; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
//GeoCoder Address::createFromArray expects longitude/latitude keys |
|
193
|
2 |
|
$data['address']['longitude'] = $data['address']['coordinates']['longitude'] ?? null; |
|
194
|
2 |
|
$data['address']['latitude'] = $data['address']['coordinates']['latitude'] ?? null; |
|
195
|
|
|
|
|
196
|
|
|
// Shortcut to create the address and set it in this class |
|
197
|
|
|
$this->setAddress(Address::createFromArray($data['address'])); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Router all other methods call directly to our address object |
|
202
|
|
|
* |
|
203
|
|
|
* @param $method |
|
204
|
|
|
* @param $args |
|
205
|
|
|
* @return mixed |
|
206
|
|
|
*/ |
|
207
|
|
|
public function __call($method, $args) |
|
208
|
|
|
{ |
|
209
|
|
|
if (null === $this->address) { |
|
210
|
|
|
return null; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return call_user_func_array([$this->address, $method], $args); |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|