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;
23 * Class WeatherHistory.
25 class WeatherHistory implements \Iterator
28 * The city object. IMPORTANT: Not all values will be set
35 * The time needed to calculate the request data.
42 * An array of {@link WeatherHistory} objects.
46 * @see WeatherForecast The WeatherForecast class.
53 private $position = 0;
55 public function __construct($weatherHistory, $query)
57 if (isset($weatherHistory['list'][0]['city'])) {
58 $country = $weatherHistory['list'][0]['city']['country'];
59 $population = $weatherHistory['list'][0]['city']['population'];
65 $this->city = new OpenWeatherMap\Util\City($weatherHistory['city_id'], (is_string($query)) ? $query : null, (isset($query['lon'])) ? $query['lon'] : null, (isset($query['lat'])) ? $query['lat'] : null, $country, $population);
66 $this->calctime = $weatherHistory['calctime'];
68 foreach ($weatherHistory['list'] as $history) {
69 if (isset($history['rain'])) {
70 $units = array_keys($history['rain']);
72 $units = array(0 => null);
75 $this->histories[] = new History($this->city, $history['weather'][0], array('now' => $history['main']['temp'], 'min' => $history['main']['temp_min'], 'max' => $history['main']['temp_max']), $history['main']['pressure'], $history['main']['humidity'], $history['clouds']['all'], isset($history['rain']) ? array('val' => $history['rain'][($units[0])], 'unit' => $units[0]) : null, $history['wind'], \DateTime::createFromFormat('U', $history['dt']));
82 public function rewind()
90 public function current()
92 return $this->histories[$this->position];
100 return $this->position;
106 public function next()
114 public function valid()
116 return isset($this->histories[$this->position]);