/
WeatherUnderground.php
83 lines (76 loc) · 2.35 KB
/
WeatherUnderground.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* This file contains the Horde_Service_Weather_Forecast class for abstracting
* access to forecast data from Weatherunderground.
*
* Copyright 2011-2014 Horde LLC (http://www.horde.org/)
*
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Service_Weather
*/
/**
* Horde_Service_Weather_Forecast_WeatherUnderground
*
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @category Horde
* @package Service_Weather
*/
class Horde_Service_Weather_Forecast_WeatherUnderground extends Horde_Service_Weather_Forecast_Base
{
/**
* @see Horde_Service_Weather_Forecast_Base::$fields
*/
public $fields = array(
Horde_Service_Weather::FORECAST_FIELD_WIND,
Horde_Service_Weather::FORECAST_FIELD_HUMIDITY,
Horde_Service_Weather::FORECAST_FIELD_PRECIPITATION);
/**
* Const'r
*
* @see Horde_Service_Weather_Forecast_Base::__construct()
*/
public function __construct(
$properties,
Horde_Service_Weather_Base $weather,
$type = Horde_Service_Weather::FORECAST_TYPE_STANDARD)
{
parent::__construct($properties, $weather, $type);
switch ($type) {
case Horde_Service_Weather::FORECAST_TYPE_STANDARD:
$this->_parseStd();
break;
case Horde_Service_Weather::FORECAST_TYPE_HOURLY:
$this->_parseHourly();
}
}
/**
* Return the forecast time.
*
* @see Horde_Service_Weather_Forecast_Base::getForecastTime()
*/
public function getForecastTime()
{
return new Horde_Date($this->_properties['txt_forecast']->date);
}
/**
* Parse the Std forecast data
*
* @throws Horde_Service_Weather_Exception
*/
protected function _parseStd()
{
if (empty($this->_properties)) {
throw new Horde_Service_Weather_Exception('No forecast data to parse.');
}
foreach ($this->_properties['simpleforecast']->forecastday as $period => $values) {
$this->_periods[] = new Horde_Service_Weather_Period_WeatherUnderground((array)$values, $this);
}
}
// @TODO: Use the hourly forecast to maybe get a "day"/"night"
protected function _parseHourly()
{
throw Horde_Exception('Not currently implemented.');
}
}