Symbol.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Yr\Forecast\Tabular\Time;
  3. /**
  4. * Contains the sky data, e.g «Clody» etc
  5. *
  6. * @author Joachim M. Giæver (joachim[]giaever.org)
  7. */
  8. class Symbol implements DiffInterface {
  9. private $number;
  10. private $numberEx;
  11. private $name;
  12. private $var;
  13. /**
  14. * @param \SimpleXMLElement $xml XML containing the symbol data
  15. */
  16. public function __construct(\SimpleXMLElement $xml) {
  17. $this->number = (int)$xml['number'];
  18. $this->numberEx = (int)$xml['numberEx'];
  19. $this->name = (string)$xml['name'];
  20. $this->var = (string)$xml['var'];
  21. }
  22. /**
  23. * Retuns the type identifier
  24. *
  25. * @return int
  26. */
  27. public function getNumber(): int {
  28. return $this->number;
  29. }
  30. /**
  31. * Returns the name, e.g «clody».
  32. *
  33. * @return string
  34. */
  35. public function getName(): string {
  36. return $this->name;
  37. }
  38. /**
  39. * Return the var-variable
  40. *
  41. * @return string
  42. */
  43. public function getVar(): string {
  44. return $this->var;
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function diff(DiffInterface $s): int {
  50. if ($s instanceof Symbol)
  51. return $this->number - $s->getNumber();
  52. return 0;
  53. }
  54. public function __toString(): string {
  55. return sprintf(
  56. "%s (%d, %d, %s)", $this->name,
  57. $this->number, $this->numberEx,
  58. $this->var
  59. );
  60. }
  61. }