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
|
260 |
|
public function hasLocation() |
60
|
|
|
{ |
61
|
260 |
|
return $this->location !== null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return Coordinate|null |
66
|
|
|
*/ |
67
|
16 |
|
public function getLocation() |
68
|
|
|
{ |
69
|
16 |
|
return $this->location; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param Coordinate|null $location |
74
|
|
|
*/ |
75
|
184 |
|
public function setLocation(Coordinate $location = null) |
76
|
|
|
{ |
77
|
184 |
|
$this->location = $location; |
78
|
184 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
256 |
|
public function hasRadius() |
84
|
|
|
{ |
85
|
256 |
|
return $this->radius !== null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return float |
90
|
|
|
*/ |
91
|
12 |
|
public function getRadius() |
92
|
|
|
{ |
93
|
12 |
|
return $this->radius; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param float $radius |
98
|
|
|
*/ |
99
|
176 |
|
public function setRadius($radius) |
100
|
|
|
{ |
101
|
176 |
|
$this->radius = $radius; |
102
|
176 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return bool |
106
|
|
|
*/ |
107
|
252 |
|
public function hasMinPrice() |
108
|
|
|
{ |
109
|
252 |
|
return $this->minPrice !== null; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return int|null |
114
|
|
|
*/ |
115
|
8 |
|
public function getMinPrice() |
116
|
|
|
{ |
117
|
8 |
|
return $this->minPrice; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param int|null $minPrice |
122
|
|
|
*/ |
123
|
32 |
|
public function setMinPrice($minPrice) |
124
|
|
|
{ |
125
|
32 |
|
$this->minPrice = $minPrice; |
126
|
32 |
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
252 |
|
public function hasMaxPrice() |
132
|
|
|
{ |
133
|
252 |
|
return $this->maxPrice !== null; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return int|null |
138
|
|
|
*/ |
139
|
8 |
|
public function getMaxPrice() |
140
|
|
|
{ |
141
|
8 |
|
return $this->maxPrice; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param int|null $maxPrice |
146
|
|
|
*/ |
147
|
32 |
|
public function setMaxPrice($maxPrice) |
148
|
|
|
{ |
149
|
32 |
|
$this->maxPrice = $maxPrice; |
150
|
32 |
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
252 |
|
public function hasOpenNow() |
156
|
|
|
{ |
157
|
252 |
|
return $this->openNow !== null; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return bool|null |
162
|
|
|
*/ |
163
|
8 |
|
public function isOpenNow() |
164
|
|
|
{ |
165
|
8 |
|
return $this->openNow; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param bool|null $openNow |
170
|
|
|
*/ |
171
|
28 |
|
public function setOpenNow($openNow) |
172
|
|
|
{ |
173
|
28 |
|
$this->openNow = $openNow; |
174
|
28 |
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return bool |
178
|
|
|
*/ |
179
|
252 |
|
public function hasType() |
180
|
|
|
{ |
181
|
252 |
|
return $this->type !== null; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return string|null |
186
|
|
|
*/ |
187
|
8 |
|
public function getType() |
188
|
|
|
{ |
189
|
8 |
|
return $this->type; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param string|null $type |
194
|
|
|
*/ |
195
|
36 |
|
public function setType($type) |
196
|
|
|
{ |
197
|
36 |
|
$this->type = $type; |
198
|
36 |
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return bool |
202
|
|
|
*/ |
203
|
252 |
|
public function hasLanguage() |
204
|
|
|
{ |
205
|
252 |
|
return $this->language !== null; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return string|null |
210
|
|
|
*/ |
211
|
8 |
|
public function getLanguage() |
212
|
|
|
{ |
213
|
8 |
|
return $this->language; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param string|null $language |
218
|
|
|
*/ |
219
|
32 |
|
public function setLanguage($language) |
220
|
|
|
{ |
221
|
32 |
|
$this->language = $language; |
222
|
32 |
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* {@inheritdoc} |
226
|
|
|
*/ |
227
|
244 |
|
public function buildQuery() |
228
|
|
|
{ |
229
|
244 |
|
$query = []; |
230
|
|
|
|
231
|
244 |
|
if ($this->hasLocation()) { |
232
|
152 |
|
$query['location'] = $this->buildCoordinate($this->location); |
|
|
|
|
233
|
76 |
|
} |
234
|
|
|
|
235
|
244 |
|
if ($this->hasRadius()) { |
236
|
140 |
|
$query['radius'] = $this->radius; |
237
|
70 |
|
} |
238
|
|
|
|
239
|
244 |
|
if ($this->hasMinPrice()) { |
240
|
28 |
|
$query['minprice'] = $this->minPrice; |
241
|
14 |
|
} |
242
|
|
|
|
243
|
244 |
|
if ($this->hasMaxPrice()) { |
244
|
28 |
|
$query['maxprice'] = $this->maxPrice; |
245
|
14 |
|
} |
246
|
|
|
|
247
|
244 |
|
if ($this->hasOpenNow()) { |
248
|
24 |
|
$query['opennow'] = $this->openNow; |
249
|
12 |
|
} |
250
|
|
|
|
251
|
244 |
|
if ($this->hasType()) { |
252
|
32 |
|
$query['type'] = $this->type; |
253
|
16 |
|
} |
254
|
|
|
|
255
|
244 |
|
if ($this->hasLanguage()) { |
256
|
28 |
|
$query['language'] = $this->language; |
257
|
14 |
|
} |
258
|
|
|
|
259
|
244 |
|
return $query; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param Coordinate $place |
264
|
|
|
* |
265
|
|
|
* @return string |
266
|
|
|
*/ |
267
|
152 |
|
private function buildCoordinate(Coordinate $place) |
268
|
|
|
{ |
269
|
152 |
|
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: