Time.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Yr\Forecast\Tabular;
  3. use App\Yr\Forecast\Tabular\Time\Pressure;
  4. use App\Yr\Forecast\Tabular\Time\Symbol;
  5. use App\Yr\Forecast\Tabular\Time\Temperature;
  6. use App\Yr\Forecast\Tabular\Time\WindDirection;
  7. use App\Yr\Forecast\Tabular\Time\WindSpeed;
  8. final class Time implements \IteratorAggregate {
  9. private $from;
  10. private $until;
  11. private $period;
  12. private $symbol;
  13. private $windDirection;
  14. public function __construct(\SimpleXMLElement $xml) {
  15. $this->from = new \DateTimeImmutable($xml['from']);
  16. $this->until = new \DateTimeImmutable($xml['to']);
  17. $this->period = (int)$xml['period'];
  18. $this->symbol = new Symbol($xml->symbol);
  19. $this->windDirection = new WindDirection($xml->windDirection);
  20. $this->windSpeed= new WindSpeed($xml->windSpeed);
  21. $this->temperature = new Temperature($xml->temperature);
  22. $this->pressure = new Pressure($xml->pressure);
  23. }
  24. public function getPeriod(): int {
  25. return $this->period;
  26. }
  27. public function getFrom(): \DateTimeImmutable {
  28. return $this->from;
  29. }
  30. public function getUntil(): \DateTimeImmutable {
  31. return $this->until;
  32. }
  33. public function getSymbol(): Symbol {
  34. return $this->symbol;
  35. }
  36. public function getWindDirection(): WindDirection {
  37. return $this->getWindDirection();
  38. }
  39. public function getWindSpeed(): WindSpeed {
  40. return $this->windSpeed;
  41. }
  42. public function getTemperature(): Temperature {
  43. return $this->temperature;
  44. }
  45. public function getPressure(): Pressure {
  46. return $this->pressure;
  47. }
  48. public function getIterator(): \Generator {
  49. foreach ([
  50. $this->getSymbol(),
  51. $this->getWindDirection(),
  52. $this->getWindSpeed(),
  53. $this->getTemperature(),
  54. $this->getPressure(),
  55. ] as $entity)
  56. yield $entity;
  57. }
  58. public function __toString(): string {
  59. return sprintf(
  60. '%s - %s: %s, %s, %s, %s, %s',
  61. $this->from->format('H:i'), $this->until->format('H:i'),
  62. $this->symbol, $this->windDirection, $this->windSpeed,
  63. $this->temperature, $this->pressure
  64. );
  65. }
  66. }