|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org . |
|
4
|
|
|
* |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
* |
|
7
|
|
|
* Please see the LICENSE file distributed with this source code for further |
|
8
|
|
|
* information regarding copyright and licensing. |
|
9
|
|
|
* |
|
10
|
|
|
* Please visit the following links to read about the usage policies and the license of |
|
11
|
|
|
* OpenWeatherMap before using this class: |
|
12
|
|
|
* |
|
13
|
|
|
* @see http://www.OpenWeatherMap.org |
|
14
|
|
|
* @see http://www.OpenWeatherMap.org/terms |
|
15
|
|
|
* @see http://openweathermap.org/appid |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Cmfcmf\OpenWeatherMap\Util; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The temperature class representing a temperature object. |
|
22
|
|
|
*/ |
|
23
|
|
|
class Temperature |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var Unit The current temperature. |
|
27
|
|
|
*/ |
|
28
|
|
|
public $now; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Unit The minimal temperature. |
|
32
|
|
|
*/ |
|
33
|
|
|
public $min; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Unit The maximal temperature. |
|
37
|
|
|
*/ |
|
38
|
|
|
public $max; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var Unit The day temperature. Might not be null. |
|
42
|
|
|
*/ |
|
43
|
|
|
public $day; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var Unit The morning temperature. Might not be null. |
|
47
|
|
|
*/ |
|
48
|
|
|
public $morning; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var Unit The evening temperature. Might not be null. |
|
52
|
|
|
*/ |
|
53
|
|
|
public $evening; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var Unit The night temperature. Might not be null. |
|
57
|
|
|
*/ |
|
58
|
|
|
public $night; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the current temperature as formatted string. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string The current temperature as a formatted string. |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function __toString() |
|
66
|
|
|
{ |
|
67
|
3 |
|
return $this->now->__toString(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the current temperature's unit. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string The current temperature's unit. |
|
74
|
|
|
*/ |
|
75
|
3 |
|
public function getUnit() |
|
76
|
|
|
{ |
|
77
|
3 |
|
return $this->now->getUnit(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Returns the current temperature. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string The current temperature. |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function getValue() |
|
86
|
|
|
{ |
|
87
|
3 |
|
return $this->now->getValue(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the current temperature's description. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string The current temperature's description. |
|
94
|
|
|
*/ |
|
95
|
2 |
|
public function getDescription() |
|
96
|
|
|
{ |
|
97
|
2 |
|
return $this->now->getDescription(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Returns the current temperature as formatted string. |
|
102
|
|
|
* |
|
103
|
|
|
* @return string The current temperature as formatted string. |
|
104
|
|
|
*/ |
|
105
|
3 |
|
public function getFormatted() |
|
106
|
|
|
{ |
|
107
|
3 |
|
return $this->now->getFormatted(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Create a new temperature object. |
|
112
|
|
|
* |
|
113
|
|
|
* @param Unit $now The current temperature. |
|
114
|
|
|
* @param Unit $min The minimal temperature. |
|
115
|
|
|
* @param Unit $max The maximal temperature. |
|
116
|
|
|
* @param Unit $day The day temperature. Might not be null. |
|
117
|
|
|
* @param Unit $morning The morning temperature. Might not be null. |
|
118
|
|
|
* @param Unit $evening The evening temperature. Might not be null. |
|
119
|
|
|
* @param Unit $night The night temperature. Might not be null. |
|
120
|
|
|
* |
|
121
|
|
|
* @internal |
|
122
|
|
|
*/ |
|
123
|
7 |
|
public function __construct(Unit $now, Unit $min, Unit $max, Unit $day = null, Unit $morning = null, Unit $evening = null, Unit $night = null) |
|
124
|
|
|
{ |
|
125
|
7 |
|
$this->now = $now; |
|
126
|
7 |
|
$this->min = $min; |
|
127
|
7 |
|
$this->max = $max; |
|
128
|
7 |
|
$this->day = $day; |
|
129
|
7 |
|
$this->morning = $morning; |
|
130
|
7 |
|
$this->evening = $evening; |
|
131
|
7 |
|
$this->night = $night; |
|
132
|
7 |
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|