/**
  * @param  \SimpleXMLElement         $xml
  * @return TextualForecast
  * @throws \InvalidArgumentException
  */
 public static function createTextualForecastFromXml(\SimpleXMLElement $xml)
 {
     $data = Yr::xmlToArray($xml);
     $title = $data['title'];
     $text = $data['body'];
     $from = \DateTime::createFromFormat(TextualForecast::XML_DATE_FORMAT, $data['from']);
     $to = \DateTime::createFromFormat(TextualForecast::XML_DATE_FORMAT, $data['to']);
     return new TextualForecast($title, $text, $from, $to);
 }
예제 #2
0
 /**
  * Creates from simplexml object.
  *
  * @param \SimpleXMLElement $xml The xml node element
  *
  * @return Forecast
  *
  * @throws \RuntimeException If some data is missing for xml
  */
 public static function getForecastFromXml(\SimpleXMLElement $xml)
 {
     $forecast = new Forecast();
     $data = Yr::xmlToArray($xml);
     if (!isset($data['from'], $data['to'])) {
         throw new \RuntimeException("Missing from/to for forecast");
     }
     $forecast->from = \DateTime::createFromFormat(Yr::XML_DATE_FORMAT, $data['from']);
     $forecast->to = \DateTime::createFromFormat(Yr::XML_DATE_FORMAT, $data['to']);
     $forecast->period = isset($data['period']) ? $data['period'] : "";
     if (!isset($data['symbol'], $data['precipitation'], $data['windDirection'], $data['windSpeed'], $data['temperature'], $data['pressure'])) {
         throw new \RuntimeException("Missing data for forecast");
     }
     $forecast->symbol = $data['symbol'];
     $forecast->precipitation = $data['precipitation'];
     $forecast->wind_direction = $data['windDirection'];
     $forecast->wind_speed = $data['windSpeed'];
     $forecast->temperature = $data['temperature'];
     $forecast->pressure = $data['pressure'];
     return $forecast;
 }
예제 #3
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return WeatherStation
  */
 public static function getWeatherStationFromXml(\SimpleXMLElement $xml)
 {
     $data = Yr::xmlToArray($xml);
     $name = $data['name'];
     $distance = $data['distance'];
     $latLong = array('lat' => $data['lat'], 'long' => $data['lon']);
     $source = $data['source'];
     $station = new WeatherStation($name, $distance, $latLong, $source);
     $forecast = $station->getForecast();
     if (isset($data['symbol'])) {
         $forecast->setSymbol($data['symbol']);
     }
     if (isset($data['temperature'])) {
         $forecast->setTemperature($data['temperature']);
     }
     if (isset($data['windDirection'])) {
         $forecast->setWindDirection($data['windDirection']);
     }
     if (isset($data['windSpeed'])) {
         $forecast->setWindSpeed($data['windSpeed']);
     }
     return $station;
 }