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\Geocoder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest |
16
|
|
|
* |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractGeocoderReverseRequest extends AbstractGeocoderRequest |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string[] |
23
|
|
|
*/ |
24
|
|
|
private $resultTypes = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string[] |
28
|
|
|
*/ |
29
|
|
|
private $locationTypes = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
|
|
public function hasResultTypes() |
35
|
|
|
{ |
36
|
|
|
return !empty($this->resultTypes); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string[] |
41
|
|
|
*/ |
42
|
|
|
public function getResultTypes() |
43
|
|
|
{ |
44
|
|
|
return $this->resultTypes; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string[] $resultTypes |
49
|
|
|
*/ |
50
|
|
|
public function setResultTypes(array $resultTypes) |
51
|
|
|
{ |
52
|
|
|
$this->resultTypes = []; |
53
|
|
|
$this->addResultTypes($resultTypes); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string[] $resultTypes |
58
|
|
|
*/ |
59
|
|
|
public function addResultTypes(array $resultTypes) |
60
|
|
|
{ |
61
|
|
|
foreach ($resultTypes as $resultType) { |
62
|
|
|
$this->addResultType($resultType); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $resultType |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
public function hasResultType($resultType) |
72
|
|
|
{ |
73
|
|
|
return in_array($resultType, $this->resultTypes, true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $resultType |
78
|
|
|
*/ |
79
|
|
|
public function addResultType($resultType) |
80
|
|
|
{ |
81
|
|
|
if (!$this->hasResultType($resultType)) { |
82
|
|
|
$this->resultTypes[] = $resultType; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $resultType |
88
|
|
|
*/ |
89
|
|
|
public function removeResultType($resultType) |
90
|
|
|
{ |
91
|
|
|
unset($this->resultTypes[array_search($resultType, $this->resultTypes, true)]); |
92
|
|
|
$this->resultTypes = array_values($this->resultTypes); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
|
|
public function hasLocationTypes() |
99
|
|
|
{ |
100
|
|
|
return !empty($this->locationTypes); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string[] |
105
|
|
|
*/ |
106
|
|
|
public function getLocationTypes() |
107
|
|
|
{ |
108
|
|
|
return $this->locationTypes; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string[] $locationTypes |
113
|
|
|
*/ |
114
|
|
|
public function setLocationTypes(array $locationTypes) |
115
|
|
|
{ |
116
|
|
|
$this->locationTypes = []; |
117
|
|
|
$this->addLocationTypes($locationTypes); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param string[] $locationTypes |
122
|
|
|
*/ |
123
|
|
|
public function addLocationTypes(array $locationTypes) |
124
|
|
|
{ |
125
|
|
|
foreach ($locationTypes as $locationType) { |
126
|
|
|
$this->addLocationType($locationType); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $locationType |
132
|
|
|
* |
133
|
|
|
* @return bool |
134
|
|
|
*/ |
135
|
|
|
public function hasLocationType($locationType) |
136
|
|
|
{ |
137
|
|
|
return in_array($locationType, $this->locationTypes, true); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $locationType |
142
|
|
|
*/ |
143
|
|
|
public function addLocationType($locationType) |
144
|
|
|
{ |
145
|
|
|
if (!$this->hasLocationType($locationType)) { |
146
|
|
|
$this->locationTypes[] = $locationType; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $locationType |
152
|
|
|
*/ |
153
|
|
|
public function removeLocationType($locationType) |
154
|
|
|
{ |
155
|
|
|
unset($this->locationTypes[array_search($locationType, $this->locationTypes, true)]); |
156
|
|
|
$this->locationTypes = array_values($this->locationTypes); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritdoc} |
161
|
|
|
*/ |
162
|
|
|
public function buildQuery() |
163
|
|
|
{ |
164
|
|
|
$query = []; |
165
|
|
|
|
166
|
|
|
if ($this->hasResultTypes()) { |
167
|
|
|
$query['result_type'] = implode('|', $this->resultTypes); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
if ($this->hasLocationTypes()) { |
171
|
|
|
$query['location_type'] = implode('|', $this->locationTypes); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return array_merge(parent::buildQuery(), $query); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|