1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the geo-api-library package. |
5
|
|
|
* |
6
|
|
|
* (c) 2020 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Library\GeoAPI\Request\Adresse; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Model\Attribute\StringTypeTrait; |
15
|
|
|
use WBW\Library\GeoAPI\Model\Attribute\FloatLatTrait; |
16
|
|
|
use WBW\Library\GeoAPI\Model\Attribute\FloatLonTrait; |
17
|
|
|
use WBW\Library\GeoAPI\Request\AbstractRequest; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Search request. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Library\GeoAPI\Request\Adresse |
24
|
|
|
*/ |
25
|
|
|
class SearchRequest extends AbstractRequest { |
26
|
|
|
|
27
|
|
|
use FloatLatTrait; |
28
|
|
|
use FloatLonTrait; |
29
|
|
|
use StringTypeTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Resource path. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
const RESOURCE_PATH = "/search/"; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Type "house number". |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
const TYPE_HOUSE_NUMBER = "housenumber"; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Type "locality". |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
const TYPE_LOCALITY = "locality"; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Type "municipality". |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
const TYPE_MUNICIPALITY = "municipality"; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Type "street". |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
const TYPE_STREET = "street"; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Autocomplete. |
68
|
|
|
* |
69
|
|
|
* @var bool|null |
70
|
|
|
*/ |
71
|
|
|
private $autocomplete; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* City code. |
75
|
|
|
* |
76
|
|
|
* @var string|null |
77
|
|
|
*/ |
78
|
|
|
private $cityCode; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Limit. |
82
|
|
|
* |
83
|
|
|
* @var int|null |
84
|
|
|
*/ |
85
|
|
|
private $limit; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Postcode. |
89
|
|
|
* |
90
|
|
|
* @var string|null |
91
|
|
|
*/ |
92
|
|
|
private $postcode; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Query. |
96
|
|
|
* |
97
|
|
|
* @var string|null |
98
|
|
|
*/ |
99
|
|
|
private $q; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Constructor. |
103
|
|
|
* |
104
|
|
|
* @param string|null $q The query. |
105
|
|
|
*/ |
106
|
|
|
public function __construct(string $q = null) { |
107
|
|
|
parent::__construct(); |
108
|
|
|
$this->setQ($q); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Enumerates the types. |
113
|
|
|
* |
114
|
|
|
* @return string[] Returns the types. |
115
|
|
|
*/ |
116
|
|
|
public static function enumTypes(): array { |
117
|
|
|
return [ |
118
|
|
|
self::TYPE_HOUSE_NUMBER, |
119
|
|
|
self::TYPE_LOCALITY, |
120
|
|
|
self::TYPE_MUNICIPALITY, |
121
|
|
|
self::TYPE_STREET, |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get the autocomplete. |
127
|
|
|
* |
128
|
|
|
* @return bool|null Returns the autocomplete. |
129
|
|
|
*/ |
130
|
|
|
public function getAutocomplete(): ?bool { |
131
|
|
|
return $this->autocomplete; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get the city code. |
136
|
|
|
* |
137
|
|
|
* @return string|null Returns the city code. |
138
|
|
|
*/ |
139
|
|
|
public function getCityCode(): ?string { |
140
|
|
|
return $this->cityCode; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the limit. |
145
|
|
|
* |
146
|
|
|
* @return int|null Returns the limit. |
147
|
|
|
*/ |
148
|
|
|
public function getLimit(): ?int { |
149
|
|
|
return $this->limit; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Get the postcode. |
154
|
|
|
* |
155
|
|
|
* @return string|null Returns the postcode. |
156
|
|
|
*/ |
157
|
|
|
public function getPostcode(): ?string { |
158
|
|
|
return $this->postcode; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get the query. |
163
|
|
|
* |
164
|
|
|
* @return string|null Returns the query. |
165
|
|
|
*/ |
166
|
|
|
public function getQ(): ?string { |
167
|
|
|
return $this->q; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* {@inheritDoc} |
172
|
|
|
*/ |
173
|
|
|
public function getResourcePath(): string { |
174
|
|
|
return self::RESOURCE_PATH; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Get the autocomplete. |
179
|
|
|
* |
180
|
|
|
* @param bool|null $autocomplete The autocomplete. |
181
|
|
|
* @return SearchRequest Returns this search request. |
182
|
|
|
*/ |
183
|
|
|
public function setAutocomplete(?bool $autocomplete): SearchRequest { |
184
|
|
|
$this->autocomplete = $autocomplete; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Set the city code. |
190
|
|
|
* |
191
|
|
|
* @param string|null $cityCode The city code. |
192
|
|
|
* @return SearchRequest Returns this search request. |
193
|
|
|
*/ |
194
|
|
|
public function setCityCode(?string $cityCode): SearchRequest { |
195
|
|
|
$this->cityCode = $cityCode; |
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Set the limit. |
201
|
|
|
* |
202
|
|
|
* @param int|null $limit The limit. |
203
|
|
|
* @return SearchRequest Returns this search request. |
204
|
|
|
*/ |
205
|
|
|
public function setLimit(?int $limit): SearchRequest { |
206
|
|
|
$this->limit = $limit; |
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Set the postcode. |
212
|
|
|
* |
213
|
|
|
* @param string|null $postcode The postcode. |
214
|
|
|
* @return SearchRequest Returns this search request. |
215
|
|
|
*/ |
216
|
|
|
public function setPostcode(?string $postcode): SearchRequest { |
217
|
|
|
$this->postcode = $postcode; |
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Set the query. |
223
|
|
|
* |
224
|
|
|
* @param string|null $q The query. |
225
|
|
|
* @return SearchRequest Returns this search request. |
226
|
|
|
*/ |
227
|
|
|
public function setQ(?string $q): SearchRequest { |
228
|
|
|
$this->q = $q; |
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
} |