3 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
7 * Please see the LICENSE file distributed with this source code for further
8 * information regarding copyright and licensing.
10 * Please visit the following links to read about the usage policies and the license of
11 * OpenWeatherMap before using this class:
13 * @see http://www.OpenWeatherMap.org
14 * @see http://www.OpenWeatherMap.org/terms
15 * @see http://openweathermap.org/appid
18 namespace Cmfcmf\OpenWeatherMap;
20 use Cmfcmf\OpenWeatherMap;
21 use Cmfcmf\OpenWeatherMap\Util\City;
22 use Cmfcmf\OpenWeatherMap\Util\Sun;
25 * Weather class returned by Cmfcmf\OpenWeatherMap->getWeather().
27 * @see Cmfcmf\OpenWeatherMap::getWeather() The function using it.
29 class WeatherForecast implements \Iterator
46 * The time of the last update of this weather data.
53 * An array of {@link WeatherForecast} objects.
57 * @see WeatherForecast The WeatherForecast class.
64 private $position = 0;
67 * Create a new Forecast object.
70 * @param string $units
71 * @param int $days How many days of forecast to receive.
75 public function __construct($xml, $units, $days)
77 $this->city = new City(-1, $xml->location->name, $xml->location->location['longitude'], $xml->location->location['latitude'], $xml->location->country);
78 $this->sun = new Sun(new \DateTime($xml->sun['rise']), new \DateTime($xml->sun['set']));
79 $this->lastUpdate = new \DateTime($xml->meta->lastupdate);
82 foreach ($xml->forecast->time as $time) {
83 $forecast = new Forecast($time, $units);
84 $forecast->city = $this->city;
85 $this->forecasts[] = $forecast;
88 // Make sure to only return the requested number of days.
89 if ($days <= 5 && $counter == $days * 8) {
91 } else if ($days > 5 && $counter == $days) {
100 public function rewind()
108 public function current()
110 return $this->forecasts[$this->position];
116 public function key()
118 return $this->position;
124 public function next()
132 public function valid()
134 return isset($this->forecasts[$this->position]);