|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ivory Google Map package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Service\Place\Search\Request; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author GeLo <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractPlaceSearchRequest implements PlaceSearchRequestInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Coordinate|null |
|
23
|
|
|
*/ |
|
24
|
|
|
private $location; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var float|null |
|
28
|
|
|
*/ |
|
29
|
|
|
private $radius; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var int|null |
|
33
|
|
|
*/ |
|
34
|
|
|
private $minPrice; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var int|null |
|
38
|
|
|
*/ |
|
39
|
|
|
private $maxPrice; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var bool|null |
|
43
|
|
|
*/ |
|
44
|
|
|
private $openNow; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string|null |
|
48
|
|
|
*/ |
|
49
|
|
|
private $type; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var string|null |
|
53
|
|
|
*/ |
|
54
|
|
|
private $language; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function hasLocation() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->location !== null; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return Coordinate|null |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getLocation() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->location; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param Coordinate|null $location |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setLocation(Coordinate $location = null) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->location = $location; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
|
|
public function hasRadius() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->radius !== null; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return float |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getRadius() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->radius; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param float $radius |
|
98
|
|
|
*/ |
|
99
|
|
|
public function setRadius($radius) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->radius = $radius; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
|
|
public function hasMinPrice() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->minPrice !== null; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return int|null |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getMinPrice() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->minPrice; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param int|null $minPrice |
|
122
|
|
|
*/ |
|
123
|
|
|
public function setMinPrice($minPrice) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->minPrice = $minPrice; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return bool |
|
130
|
|
|
*/ |
|
131
|
|
|
public function hasMaxPrice() |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->maxPrice !== null; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return int|null |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getMaxPrice() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->maxPrice; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param int|null $maxPrice |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setMaxPrice($maxPrice) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->maxPrice = $maxPrice; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return bool |
|
154
|
|
|
*/ |
|
155
|
|
|
public function hasOpenNow() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->openNow !== null; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return bool|null |
|
162
|
|
|
*/ |
|
163
|
|
|
public function isOpenNow() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->openNow; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param bool|null $openNow |
|
170
|
|
|
*/ |
|
171
|
|
|
public function setOpenNow($openNow) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->openNow = $openNow; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return bool |
|
178
|
|
|
*/ |
|
179
|
|
|
public function hasType() |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->type !== null; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return string|null |
|
186
|
|
|
*/ |
|
187
|
|
|
public function getType() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->type; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param string|null $type |
|
194
|
|
|
*/ |
|
195
|
|
|
public function setType($type) |
|
196
|
|
|
{ |
|
197
|
|
|
$this->type = $type; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @return bool |
|
202
|
|
|
*/ |
|
203
|
|
|
public function hasLanguage() |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->language !== null; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return string|null |
|
210
|
|
|
*/ |
|
211
|
|
|
public function getLanguage() |
|
212
|
|
|
{ |
|
213
|
|
|
return $this->language; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param string|null $language |
|
218
|
|
|
*/ |
|
219
|
|
|
public function setLanguage($language) |
|
220
|
|
|
{ |
|
221
|
|
|
$this->language = $language; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* {@inheritdoc} |
|
226
|
|
|
*/ |
|
227
|
|
|
public function buildQuery() |
|
228
|
|
|
{ |
|
229
|
|
|
$query = []; |
|
230
|
|
|
|
|
231
|
|
|
if ($this->hasLocation()) { |
|
232
|
|
|
$query['location'] = $this->buildCoordinate($this->location); |
|
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
if ($this->hasRadius()) { |
|
236
|
|
|
$query['radius'] = $this->radius; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
if ($this->hasMinPrice()) { |
|
240
|
|
|
$query['minprice'] = $this->minPrice; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
if ($this->hasMaxPrice()) { |
|
244
|
|
|
$query['maxprice'] = $this->maxPrice; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
if ($this->hasOpenNow()) { |
|
248
|
|
|
$query['opennow'] = $this->openNow; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
if ($this->hasType()) { |
|
252
|
|
|
$query['type'] = $this->type; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
if ($this->hasLanguage()) { |
|
256
|
|
|
$query['language'] = $this->language; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
return $query; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @param Coordinate $place |
|
264
|
|
|
* |
|
265
|
|
|
* @return string |
|
266
|
|
|
*/ |
|
267
|
|
|
private function buildCoordinate(Coordinate $place) |
|
268
|
|
|
{ |
|
269
|
|
|
return $place->getLatitude().','.$place->getLongitude(); |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: