1
|
|
|
<?php |
2
|
|
|
namespace Dwr\OpenWeather\Response; |
3
|
|
|
|
4
|
|
|
class Weather implements ResponseInterface |
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* @var int |
8
|
|
|
*/ |
9
|
|
|
private $id; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $name; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $coord; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $weather; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $base; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private $main; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
private $visibility; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private $wind; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
private $clouds; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var int |
53
|
|
|
*/ |
54
|
|
|
private $dt; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
private $sys; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Weather constructor. |
63
|
|
|
* @param array $data |
64
|
|
|
*/ |
65
|
|
|
public function __construct(array $data) |
66
|
|
|
{ |
67
|
|
|
foreach ($data as $key => $value) { |
68
|
|
|
if (property_exists($this, $key)) { |
69
|
|
|
$this->$key = $value; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function cityId() |
79
|
|
|
{ |
80
|
|
|
return $this->id; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function cityName() |
87
|
|
|
{ |
88
|
|
|
return $this->name; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function coord() |
95
|
|
|
{ |
96
|
|
|
return $this->coord; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
public function weather() |
103
|
|
|
{ |
104
|
|
|
return $this->weather; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function base() |
111
|
|
|
{ |
112
|
|
|
return $this->base; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
public function main() |
119
|
|
|
{ |
120
|
|
|
return $this->main; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return int |
125
|
|
|
*/ |
126
|
|
|
public function visibility() |
127
|
|
|
{ |
128
|
|
|
return $this->visibility; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return array |
133
|
|
|
*/ |
134
|
|
|
public function wind() |
135
|
|
|
{ |
136
|
|
|
return $this->wind; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function clouds() |
143
|
|
|
{ |
144
|
|
|
return $this->clouds; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return int |
149
|
|
|
*/ |
150
|
|
|
public function dt() |
151
|
|
|
{ |
152
|
|
|
return $this->dt; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return array |
157
|
|
|
*/ |
158
|
|
|
public function sys() |
159
|
|
|
{ |
160
|
|
|
return $this->sys; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function icon() |
167
|
|
|
{ |
168
|
|
|
return ($this->weather) ? $this->weather[0]['icon'] : ''; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function description() |
175
|
|
|
{ |
176
|
|
|
return ($this->weather) ? $this->weather[0]['description'] : ''; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return float|string |
181
|
|
|
*/ |
182
|
|
|
public function temp() |
183
|
|
|
{ |
184
|
|
|
return ($this->main) ? $this->main['temp'] : ''; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return float|string |
189
|
|
|
*/ |
190
|
|
|
public function pressure() |
191
|
|
|
{ |
192
|
|
|
return ($this->main) ? $this->main['pressure'] : ''; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return float|string |
197
|
|
|
*/ |
198
|
|
|
public function humidity() |
199
|
|
|
{ |
200
|
|
|
return ($this->main) ? $this->main['humidity'] : ''; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return float|string |
205
|
|
|
*/ |
206
|
|
|
public function tempMin() |
207
|
|
|
{ |
208
|
|
|
return ($this->main) ? $this->main['temp_min'] : ''; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return float|string |
213
|
|
|
*/ |
214
|
|
|
public function tempMax() |
215
|
|
|
{ |
216
|
|
|
return ($this->main) ? $this->main['temp_max'] : ''; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return float|string |
221
|
|
|
*/ |
222
|
|
|
public function windSpeed() |
223
|
|
|
{ |
224
|
|
|
return ($this->wind) ? $this->wind['speed'] : ''; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return int|string |
229
|
|
|
*/ |
230
|
|
|
public function windDeg() |
231
|
|
|
{ |
232
|
|
|
return ($this->wind) ? $this->wind['deg'] : ''; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function country() |
239
|
|
|
{ |
240
|
|
|
return ($this->sys) ? $this->sys['country'] : ''; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return int|string |
245
|
|
|
*/ |
246
|
|
|
public function sunrise() |
247
|
|
|
{ |
248
|
|
|
return ($this->sys) ? $this->sys['sunrise'] : ''; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return int|string |
253
|
|
|
*/ |
254
|
|
|
public function sunset() |
255
|
|
|
{ |
256
|
|
|
return ($this->sys) ? $this->sys['sunset'] : ''; |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|