Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Helpers;
  3. use ArrayAccess;
  4. class State implements ArrayAccess
  5. {
  6. /**
  7. * The state data array.
  8. */
  9. protected array $data;
  10. /**
  11. * Create a new state instance.
  12. */
  13. public function __construct($data)
  14. {
  15. $this->setData($data);
  16. }
  17. /**
  18. * Set the state data array.
  19. */
  20. public function setData($data): static
  21. {
  22. $this->data = $data;
  23. return $this;
  24. }
  25. /**
  26. * Get the state data array.
  27. */
  28. public function getData(): ?array
  29. {
  30. return $this->data;
  31. }
  32. /**
  33. * Set a single state data array value.
  34. */
  35. public function set($key, $value): static
  36. {
  37. $this->data[$key] = $value;
  38. return $this;
  39. }
  40. /**
  41. * Get a single state data array value.
  42. */
  43. public function get($key): mixed
  44. {
  45. return $this->data[$key] ?? null;
  46. }
  47. /**
  48. * Check if an offset exists in the data array.
  49. */
  50. public function offsetExists($offset): bool
  51. {
  52. return isset($this->data[$offset]);
  53. }
  54. /**
  55. * Get an offset from the data array.
  56. */
  57. public function offsetGet($offset): mixed
  58. {
  59. return $this->data[$offset] ?? null;
  60. }
  61. /**
  62. * Set an offset in the data array.
  63. */
  64. public function offsetSet($offset, $value): void
  65. {
  66. if ($offset === null) {
  67. $this->data[] = $value;
  68. } else {
  69. $this->data[$offset] = $value;
  70. }
  71. }
  72. /**
  73. * Unset an offset in the data array.
  74. */
  75. public function offsetUnset($offset): void
  76. {
  77. unset($this->data[$offset]);
  78. }
  79. public function getId(): ?int
  80. {
  81. return $this->get('id');
  82. }
  83. public function getName(): ?string
  84. {
  85. return $this->get('name');
  86. }
  87. public function getStateCode(): ?string
  88. {
  89. return $this->get('state_code');
  90. }
  91. public function getLatitude(): ?string
  92. {
  93. return $this->get('latitude');
  94. }
  95. public function getLongitude(): ?string
  96. {
  97. return $this->get('longitude');
  98. }
  99. public function getType(): ?string
  100. {
  101. return $this->get('type');
  102. }
  103. public function getCities(): ?array
  104. {
  105. $countryCode = $this->get('country_code');
  106. $stateCode = $this->get('state_code');
  107. return LocationDataLoader::getAllCities($countryCode, $stateCode, false)->all();
  108. }
  109. }