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