1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Ivory Google Map package. |
7
|
|
|
* |
8
|
|
|
* (c) Eric GELOEN <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please read the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ivory\GoogleMap\Service\Place\Search\Request; |
15
|
|
|
|
16
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
17
|
|
|
|
18
|
|
|
abstract class AbstractPlaceSearchRequest implements PlaceSearchRequestInterface |
19
|
|
|
{ |
20
|
|
|
/** @var Coordinate|null */ |
21
|
|
|
private $location; |
22
|
|
|
|
23
|
|
|
/** @var float|null */ |
24
|
|
|
private $radius; |
25
|
|
|
|
26
|
|
|
/** @var int|null */ |
27
|
|
|
private $minPrice; |
28
|
|
|
|
29
|
|
|
/** @var int|null */ |
30
|
|
|
private $maxPrice; |
31
|
|
|
|
32
|
|
|
/** @var bool|null */ |
33
|
|
|
private $openNow; |
34
|
|
|
|
35
|
|
|
/** @var string|null */ |
36
|
|
|
private $type; |
37
|
|
|
|
38
|
|
|
/** @var string|null */ |
39
|
|
|
private $language; |
40
|
|
|
|
41
|
14 |
|
public function hasLocation(): bool |
42
|
|
|
{ |
43
|
14 |
|
return null !== $this->location; |
44
|
|
|
} |
45
|
|
|
|
46
|
3 |
|
public function getLocation(): ?Coordinate |
47
|
|
|
{ |
48
|
3 |
|
return $this->location; |
49
|
|
|
} |
50
|
|
|
|
51
|
7 |
|
public function setLocation(Coordinate $location = null): void |
52
|
|
|
{ |
53
|
7 |
|
$this->location = $location; |
54
|
7 |
|
} |
55
|
|
|
|
56
|
13 |
|
public function hasRadius(): bool |
57
|
|
|
{ |
58
|
13 |
|
return null !== $this->radius; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
public function getRadius(): ?float |
62
|
|
|
{ |
63
|
2 |
|
return $this->radius; |
64
|
|
|
} |
65
|
|
|
|
66
|
7 |
|
public function setRadius(?float $radius): void |
67
|
|
|
{ |
68
|
7 |
|
$this->radius = $radius; |
69
|
7 |
|
} |
70
|
|
|
|
71
|
13 |
|
public function hasMinPrice(): bool |
72
|
|
|
{ |
73
|
13 |
|
return null !== $this->minPrice; |
74
|
|
|
} |
75
|
|
|
|
76
|
2 |
|
public function getMinPrice(): ?int |
77
|
|
|
{ |
78
|
2 |
|
return $this->minPrice; |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
public function setMinPrice(?int $minPrice): void |
82
|
|
|
{ |
83
|
2 |
|
$this->minPrice = $minPrice; |
84
|
2 |
|
} |
85
|
|
|
|
86
|
13 |
|
public function hasMaxPrice(): bool |
87
|
|
|
{ |
88
|
13 |
|
return null !== $this->maxPrice; |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
public function getMaxPrice(): ?int |
92
|
|
|
{ |
93
|
2 |
|
return $this->maxPrice; |
94
|
|
|
} |
95
|
|
|
|
96
|
2 |
|
public function setMaxPrice(?int $maxPrice): void |
97
|
|
|
{ |
98
|
2 |
|
$this->maxPrice = $maxPrice; |
99
|
2 |
|
} |
100
|
|
|
|
101
|
13 |
|
public function hasOpenNow(): bool |
102
|
|
|
{ |
103
|
13 |
|
return null !== $this->openNow; |
104
|
|
|
} |
105
|
|
|
|
106
|
2 |
|
public function isOpenNow(): ?bool |
107
|
|
|
{ |
108
|
2 |
|
return $this->openNow; |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
public function setOpenNow(?bool $openNow): void |
112
|
|
|
{ |
113
|
1 |
|
$this->openNow = $openNow; |
114
|
1 |
|
} |
115
|
|
|
|
116
|
13 |
|
public function hasType(): bool |
117
|
|
|
{ |
118
|
13 |
|
return null !== $this->type; |
119
|
|
|
} |
120
|
|
|
|
121
|
2 |
|
public function getType(): ?string |
122
|
|
|
{ |
123
|
2 |
|
return $this->type; |
124
|
|
|
} |
125
|
|
|
|
126
|
2 |
|
public function setType(?string $type): void |
127
|
|
|
{ |
128
|
2 |
|
$this->type = $type; |
129
|
2 |
|
} |
130
|
|
|
|
131
|
13 |
|
public function hasLanguage(): bool |
132
|
|
|
{ |
133
|
13 |
|
return null !== $this->language; |
134
|
|
|
} |
135
|
|
|
|
136
|
2 |
|
public function getLanguage(): ?string |
137
|
|
|
{ |
138
|
2 |
|
return $this->language; |
139
|
|
|
} |
140
|
|
|
|
141
|
2 |
|
public function setLanguage(?string $language): void |
142
|
|
|
{ |
143
|
2 |
|
$this->language = $language; |
144
|
2 |
|
} |
145
|
|
|
|
146
|
11 |
|
public function buildQuery(): array |
147
|
|
|
{ |
148
|
11 |
|
$query = []; |
149
|
|
|
|
150
|
11 |
|
if ($this->hasLocation()) { |
151
|
2 |
|
$query['location'] = $this->buildCoordinate($this->location); |
152
|
|
|
} |
153
|
|
|
|
154
|
11 |
|
if ($this->hasRadius()) { |
155
|
1 |
|
$query['radius'] = $this->radius; |
156
|
|
|
} |
157
|
|
|
|
158
|
11 |
|
if ($this->hasMinPrice()) { |
159
|
1 |
|
$query['minprice'] = $this->minPrice; |
160
|
|
|
} |
161
|
|
|
|
162
|
11 |
|
if ($this->hasMaxPrice()) { |
163
|
1 |
|
$query['maxprice'] = $this->maxPrice; |
164
|
|
|
} |
165
|
|
|
|
166
|
11 |
|
if ($this->hasOpenNow()) { |
167
|
|
|
$query['opennow'] = $this->openNow; |
168
|
|
|
} |
169
|
|
|
|
170
|
11 |
|
if ($this->hasType()) { |
171
|
1 |
|
$query['type'] = $this->type; |
172
|
|
|
} |
173
|
|
|
|
174
|
11 |
|
if ($this->hasLanguage()) { |
175
|
1 |
|
$query['language'] = $this->language; |
176
|
|
|
} |
177
|
|
|
|
178
|
11 |
|
return $query; |
179
|
|
|
} |
180
|
|
|
|
181
|
2 |
|
private function buildCoordinate(Coordinate $place): string |
182
|
|
|
{ |
183
|
2 |
|
return $place->getLatitude().','.$place->getLongitude(); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|