xml = simplexml_load_file($url); $this->location = new Location($this->xml->location); } /** * Returns the location data for the forecast * * @return App\Forecast\Location */ public function getLocation(): Location { return $this->location; } /** * Return the credit to Yr.no, Meterogical Institute and NRK * * @return array */ final public function getCredit(): array { return [ 'text' => (string)$this->xml->credit->link->attributes()['text'], 'url' => (string)$this->xml->credit->link->attributes()['url'] ]; } /** * Returns the time when the sun rise for the location * * @return \DateTimeImmutable */ public function getSunrise(): \DateTimeImmutable { return new \DateTimeImmutable((string)$this->xml->sun['rise']); } /** * Returns the time when the sun sets for the location * * @return DateTimeImmutable */ public function getSunset(): \DateTimeImmutable { return new \DateTimeImmutable((string)$this->xml->sun['set']); } /** * Returns links for forecasts in other formats * * @return \Generator */ public function getLinks(): \Generator { foreach ($this->xml->links->children() as $link) yield [ 'id' => (string)$link->attributes()['id'], 'url' => (string)$link->attributes()['url'], ]; } /** * Return the time when this forecast was last update * * @return \DateTimeImmutable */ public function getLastUpdate(): \DateTimeImmutable { return new DateTimeImmutable((string)$this->xml->meta->lastupdate); } /** * Return the time when this forecast will update next * * @return \DateTimeImmutable */ public function getNextUpdate(): \DateTimeImmutable { return new DateTimeImmutable((string)$this->xml->meta->nextupdate); } /** * Get the forecast data * * @return Tabular */ public function getTabular(): Tabular { return new Tabular($this->xml->forecast->tabular); } } ?>