Overview

Packages

  • Service
    • Weather

Classes

  • Horde_Service_Weather
  • Horde_Service_Weather_Base
  • Horde_Service_Weather_Current_Base
  • Horde_Service_Weather_Current_Google
  • Horde_Service_Weather_Current_WeatherUnderground
  • Horde_Service_Weather_Current_Wwo
  • Horde_Service_Weather_Exception
  • Horde_Service_Weather_Exception_InvalidProperty
  • Horde_Service_Weather_Forecast_Base
  • Horde_Service_Weather_Forecast_Google
  • Horde_Service_Weather_Forecast_WeatherUnderground
  • Horde_Service_Weather_Forecast_Wwo
  • Horde_Service_Weather_Google
  • Horde_Service_Weather_Period_Base
  • Horde_Service_Weather_Period_Google
  • Horde_Service_Weather_Period_WeatherUnderground
  • Horde_Service_Weather_Period_Wwo
  • Horde_Service_Weather_Station
  • Horde_Service_Weather_Translation
  • Horde_Service_Weather_WeatherUnderground
  • Horde_Service_Weather_Wwo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This file contains the Horde_Service_Weather_Period class for abstracting
  4:  * access to a single forecast period from Wunderground.
  5:  *
  6:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * @author   Michael J Rubinsky <mrubinsk@horde.org>
  9:  * @license  http://www.horde.org/licenses/bsd BSD
 10:  * @category Horde
 11:  * @package  Service_Weather
 12:  */
 13: 
 14: /**
 15:  * Horde_Service_Weather_Period_WeatherUnderground
 16:  *
 17:  * @author   Michael J Rubinsky <mrubinsk@horde.org>
 18:  * @category Horde
 19:  * @package  Service_Weather
 20:  */
 21: class Horde_Service_Weather_Period_Google extends Horde_Service_Weather_Period_Base
 22: {
 23:     /**
 24:      * Workaround google not returning any timestamps with each period.
 25:      *
 26:      * @var integer
 27:      */
 28:     public $period = 0;
 29: 
 30:     /**
 31:      * Property Map
 32:      *
 33:      * @TODO Figure out what to do with the 'skyicon' value - which is sometimes
 34:      *       different than the icon and icon_url. Also, should add a icon set
 35:      *       property to allow using other icon sets e.g., {icon_set_url}/{icon}.gif
 36:      *
 37:      * @var array
 38:      */
 39:     protected $_map = array(
 40:         'conditions' => 'condition',
 41:         'icon_url' => 'icon',
 42:     );
 43: 
 44:     /**
 45:      * Const'r - overrides parent by including the $period value, which should
 46:      * be the day number of the forecast (0 = today, 1 = tomorrow etc...).
 47:      *
 48:      */
 49:     public function __construct(
 50:         $properties,
 51:         Horde_Service_Weather_Forecast_Base $forecast,
 52:         $period)
 53:     {
 54:         parent::__construct($properties, $forecast);
 55:         $this->period = $period;
 56:     }
 57: 
 58:     /**
 59:      * Accessor so we can lazy-parse the results.
 60:      *
 61:      * @param string $property  The property name.
 62:      *
 63:      * @return mixed  The value of requested property
 64:      * @throws Horde_Service_Weather_Exception_InvalidProperty
 65:      */
 66:     public function __get($property)
 67:     {
 68:         switch ($property) {
 69:         case 'is_pm':
 70:         case 'hour':
 71:         case 'precipitation_percent':
 72:         case 'period':
 73:         case 'humidity':
 74:         case 'wind_speed':
 75:         case 'wind_direction':
 76:         case 'wind_degrees':
 77:         case 'wind_gust':
 78:         case 'snow_total':
 79:         case 'rain_total':
 80:             // Not supported by Google.
 81:             return false;
 82:         case 'date':
 83:             // Do the best we can with the forecast date.
 84:             $date = new Horde_Date(time());
 85:             $date->mday += $this->period;
 86:             return $date;
 87: 
 88:         case 'high':
 89:             return round($this->_fromInternalUnits($this->_properties->high['data']));
 90: 
 91:         case 'low':
 92:             return round($this->_fromInternalUnits($this->_properties->low['data']));
 93: 
 94:         case 'icon':
 95:             return $this->_forecast->weather->iconMap[
 96:                 str_replace('.gif', '', pathinfo(parse_url((string)$this->_properties->icon['data'], PHP_URL_PATH), PATHINFO_FILENAME))
 97:             ];
 98: 
 99:         default:
100:             if (!empty($this->_map[$property])) {
101:                 return (string)$this->_properties->{$this->_map[$property]}['data'];
102:             }
103: 
104:             throw new Horde_Service_Weather_Exception_InvalidProperty('This provider does not support the "' . $property . '" property');
105:         }
106:     }
107: 
108:     /**
109:      * Convert from units Google returns value in to units we want.
110:      *
111:      * @param  float $value  The value in Google's units
112:      *
113:      *  @return float  The converted value.
114:      */
115:     protected function _fromInternalUnits($value)
116:     {
117:         if ($this->_forecast->weather->internalUnits == $this->_forecast->weather->units) {
118:             return $value;
119:         } elseif ($this->_forecast->weather->units == Horde_Service_Weather::UNITS_METRIC) {
120:             return ($value - 32) * .5556;
121:         } else {
122:             return $value * 1.8 + 32;
123:         }
124:     }
125: 
126: }
API documentation generated by ApiGen