|
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\TimeZone\Request; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author GeLo <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class TimeZoneRequest implements TimeZoneRequestInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Coordinate |
|
23
|
|
|
*/ |
|
24
|
|
|
private $location; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \DateTime |
|
28
|
|
|
*/ |
|
29
|
|
|
private $date; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string|null |
|
33
|
|
|
*/ |
|
34
|
|
|
private $language; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Coordinate $location |
|
38
|
|
|
* @param \DateTime|null $date |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(Coordinate $location, \DateTime $date = null) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->setLocation($location); |
|
43
|
|
|
$this->setDate($date); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return Coordinate |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getLocation() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->location; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param Coordinate $location |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setLocation(Coordinate $location) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->location = $location; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return \DateTime |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getDate() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->date; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param \DateTime $date |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setDate(\DateTime $date) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->date = $date; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
public function hasLanguage() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->language !== null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return string|null |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getLanguage() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->language; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string|null $language |
|
96
|
|
|
*/ |
|
97
|
|
|
public function setLanguage($language) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->language = $language; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return mixed[] |
|
104
|
|
|
*/ |
|
105
|
|
|
public function buildQuery() |
|
106
|
|
|
{ |
|
107
|
|
|
$query = [ |
|
108
|
|
|
'location' => $this->buildCoordinate($this->location), |
|
109
|
|
|
'timestamp' => $this->date->getTimestamp(), |
|
110
|
|
|
]; |
|
111
|
|
|
|
|
112
|
|
|
if ($this->hasLanguage()) { |
|
113
|
|
|
$query['language'] = $this->language; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $query; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param Coordinate $coordinate |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
private function buildCoordinate(Coordinate $coordinate) |
|
125
|
|
|
{ |
|
126
|
|
|
return $coordinate->getLatitude().','.$coordinate->getLongitude(); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):