Source for file WeatherForecastProvider.php
Documentation is available at WeatherForecastProvider.php
/* SVN FILE: $Id: WeatherForecastProvider.php 14 2009-10-13 13:43:06Z Chris $ */
* Weather Forecast Interface and Weather Forecast Objects
* @copyright Copyright 2009 PBM Web Development - All Rights Reserved
* @package weatherForecast
* @subpackage weatherForecast.providers
* @version $Revision: 14 $
* @lastmodified $Date: 2009-10-13 14:43:06 +0100 (Tue, 13 Oct 2009) $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* Weather Forecast Provider interface
* @package weatherForecast
* @subpackage weatherForecast.providers
interface IWeatherForecastProvider {
* Base class for Weather Forecast providers
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string Date format
* @link http://www.yiiframework.com/doc/api/CDateFormatter
* @var string Forecast location
* @var string Path to symbol set to use
* @var array Units for display. C=metric, F=imperial
protected function init($params, $symbols) {
foreach ($params as $param =>
$value) {
$this->symbolsDir =
$symbols[0];
if (!empty($symbols[1])) $this->symbolMap =
$symbols[1];
* Converts degrees Celcius degrees Farenheight to
* @param float $value The value to convert
* @param mixed $precision Precision of the result
* @return float The converted value
protected function c2f($value, $precision=
0) {
return round(((9/
5)*
$value)+
32, $precision);
* Converts degrees Farenheight to degrees Celcius
* @param float $value The value to convert
* @param mixed $precision Precision of the result
* @return float The converted value
protected function f2c($value, $precision=
0) {
return round((5/
9)*
($value-
32), $precision);
* @param float $value The value to convert
* @param mixed $precision Precision of the result
* @return float The converted value
protected function mph2kph($value, $precision=
0) {
return round($value *
1.609344, $precision);
* Base class for Weather Forecast providers using XML feeds
* Reads XML data and provides an DOMXPath object for querying it
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string DOMXPath Object
* @var string XML response
public function __get($name) {
throw new CException(Yii::t('WeatherForecast','Property "{class}.{property}" is not defined.',
array('{class}'=>
get_class($this), '{property}'=>
$name)));
* Reads the URL and puts the content into $this->xml
* @throws CException if unable to read the URL
protected function read($url) {
unset
($this->xpath); // ensures the feed is recognised
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//$this->xml = file_get_contents($url); // Use if PHP not compiled with cURL
throw new CException(Yii::t('WeatherForecast','Unable to read url {url}.',
* Creates a new XPath object from the XML
$doc->preserveWhiteSpace =
false;
$this->xpath =
new DOMXPath($doc);
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string Name of the data provider
* @var string Date/time the forecast was issued
* @var WFWGS84Location Forecast location
* @var CMap Days of the forecast
* Weather forecast contructor
$this->days =
new CMap();
* Weather Forecast Day class
* Records the weather forecast for a given day
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string Date for this day
* @var string Forecast description
* @var WFValue Humidity value
* @var WFValue Maximum temperature value
protected $maxTemperature;
* @var WFValue Minimum temperature value
protected $minTemperature;
* @var WFValue Atmospheric pressure value
* @var string Pressure trend
protected $pressureTrend;
* @var string Time of sunrise
* @var string Time of sunset
* @var string Path to the symbol representing the forecast
* @var WFValue Current temperature value
* @var WFValue Visibility value
* @var WFValue Wind direction
protected $windDirection;
* @var WFValue Wind speed value
* Weather Forecast Day contructor
$this->temperature =
new WFValue();
$this->maxTemperature =
new WFValue();
$this->minTemperature =
new WFValue();
$this->windDirection =
new WFValue();
* Weather Forecast Value class
* Holds a weather forecast value
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string Units of the value
* Weather Forecast Location class
* Holds a location of a weather forecast
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string Name of the location
* @var float Latitude of the location
* @var float Longitude of the location
* @var WFValue Altitude of the location
* Weather Forecast Location contructor
* Weather Forecast base class
* Provides the magic functions
* @package weatherForecast
* @subpackage weatherForecast.providers
public function __get($name) {
if(property_exists($this,$name)) return $this->$name;
public function __set($name, $value) {
if(property_exists($this,$name)) {
if(property_exists($this,$name) && isset
($this->$name)) return true;
if(property_exists($this,$name)) unset
($this->$name);
Documentation generated on Tue, 13 Oct 2009 14:44:50 +0100 by phpDocumentor 1.4.2