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\Autocomplete\Request; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractPlaceAutocompleteRequest implements PlaceAutocompleteRequestInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $input; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var int|null |
28
|
|
|
*/ |
29
|
|
|
private $offset; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Coordinate|null |
33
|
|
|
*/ |
34
|
|
|
private $location; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var float|null |
38
|
|
|
*/ |
39
|
|
|
private $radius; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string|null |
43
|
|
|
*/ |
44
|
|
|
private $language; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $input |
48
|
|
|
*/ |
49
|
208 |
|
public function __construct($input) |
50
|
|
|
{ |
51
|
208 |
|
$this->setInput($input); |
52
|
208 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
16 |
|
public function getInput() |
58
|
|
|
{ |
59
|
16 |
|
return $this->input; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $input |
64
|
|
|
*/ |
65
|
208 |
|
public function setInput($input) |
66
|
|
|
{ |
67
|
208 |
|
$this->input = $input; |
68
|
208 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
148 |
|
public function hasOffset() |
74
|
|
|
{ |
75
|
148 |
|
return $this->offset !== null; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return int|null |
80
|
|
|
*/ |
81
|
16 |
|
public function getOffset() |
82
|
|
|
{ |
83
|
16 |
|
return $this->offset; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param int|null $offset |
88
|
|
|
*/ |
89
|
24 |
|
public function setOffset($offset) |
90
|
|
|
{ |
91
|
24 |
|
$this->offset = $offset; |
92
|
24 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
148 |
|
public function hasLocation() |
98
|
|
|
{ |
99
|
148 |
|
return $this->location !== null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return Coordinate|null |
104
|
|
|
*/ |
105
|
16 |
|
public function getLocation() |
106
|
|
|
{ |
107
|
16 |
|
return $this->location; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param Coordinate|null $location |
112
|
|
|
*/ |
113
|
40 |
|
public function setLocation(Coordinate $location = null) |
114
|
|
|
{ |
115
|
40 |
|
$this->location = $location; |
116
|
40 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
148 |
|
public function hasRadius() |
122
|
|
|
{ |
123
|
148 |
|
return $this->radius !== null; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return float|null |
128
|
|
|
*/ |
129
|
16 |
|
public function getRadius() |
130
|
|
|
{ |
131
|
16 |
|
return $this->radius; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param float|null $radius |
136
|
|
|
*/ |
137
|
24 |
|
public function setRadius($radius) |
138
|
|
|
{ |
139
|
24 |
|
$this->radius = $radius; |
140
|
24 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return bool |
144
|
|
|
*/ |
145
|
148 |
|
public function hasLanguage() |
146
|
|
|
{ |
147
|
148 |
|
return $this->language !== null; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string|null |
152
|
|
|
*/ |
153
|
16 |
|
public function getLanguage() |
154
|
|
|
{ |
155
|
16 |
|
return $this->language; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string|null $language |
160
|
|
|
*/ |
161
|
24 |
|
public function setLanguage($language) |
162
|
|
|
{ |
163
|
24 |
|
$this->language = $language; |
164
|
24 |
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* {@inheritdoc} |
168
|
|
|
*/ |
169
|
132 |
|
public function buildQuery() |
170
|
|
|
{ |
171
|
132 |
|
$query = ['input' => $this->input]; |
172
|
|
|
|
173
|
132 |
|
if ($this->hasOffset()) { |
174
|
20 |
|
$query['offset'] = $this->offset; |
175
|
10 |
|
} |
176
|
|
|
|
177
|
132 |
|
if ($this->hasLocation()) { |
178
|
36 |
|
$query['location'] = $this->buildCoordinate($this->location); |
|
|
|
|
179
|
18 |
|
} |
180
|
|
|
|
181
|
132 |
|
if ($this->hasRadius()) { |
182
|
20 |
|
$query['radius'] = $this->radius; |
183
|
10 |
|
} |
184
|
|
|
|
185
|
132 |
|
if ($this->hasLanguage()) { |
186
|
20 |
|
$query['language'] = $this->language; |
187
|
10 |
|
} |
188
|
|
|
|
189
|
132 |
|
return $query; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param Coordinate $coordinate |
194
|
|
|
* |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
36 |
|
private function buildCoordinate(Coordinate $coordinate) |
198
|
|
|
{ |
199
|
36 |
|
return $coordinate->getLatitude().','.$coordinate->getLongitude(); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
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: