12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Yr;
- use App\Yr\Forecast\Location;
- use App\Yr\Forecast\Tabular;
- final class Forecast {
- private $xml;
- private $location;
- public function __construct(string $url) {
- $this->xml = simplexml_load_file($url);
- $this->location = new Location($this->xml->location);
- }
- public function getLocation(): Location {
- return $this->location;
- }
- final public function getCredit(): array {
- return [
- 'text' => (string)$this->xml->credit->link->attributes()['text'],
- 'url' => (string)$this->xml->credit->link->attributes()['url']
- ];
- }
- public function getSunrise(): \DateTimeImmutable {
- return (new \DateTimeImmutable($this->xml->sun['rise']));
- }
- public function getSunset(): \DateTimeImmutable {
- return (new \DateTimeImmutable($this->xml->sun['seẗ́']));
- }
- public function getLinks(): \Generator {
- foreach ($this->xml->links->children() as $link)
- yield [
- 'id' => (string)$link->attributes()['id'],
- 'url' => (string)$link->attributes()['url'],
- ];
- }
- public function getLastUpdate(): \DateTimeImmutable {
- return new DateTimeImmutable($this->xml->meta->lastupdate);
- }
- public function getNextUpdate(): \DateTimeImmutable {
- return new DateTimeImmutable($this->xml->meta->nextupdate);
- }
- public function getTabular(): Tabular {
- return new Tabular($this->xml->forecast->tabular);
- }
- }
- ?>
|