| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | <?php
namespace App\Helpers;
use ArrayAccess;
class City implements ArrayAccess
{
    protected array $data;
    public function __construct($data)
    {
        $this->setData($data);
    }
    /**
     * Set the city data array.
     */
    public function setData($data): static
    {
        $this->data = $data;
        return $this;
    }
    /**
     * Get the city data array.
     */
    public function getData(): ?array
    {
        return $this->data;
    }
    /**
     * Set a single city data array value.
     */
    public function set($key, $value): static
    {
        $this->data[$key] = $value;
        return $this;
    }
    /**
     * Get a single city data array value.
     */
    public function get($key): mixed
    {
        return $this->data[$key] ?? null;
    }
    /**
     * Check if an offset exists in the data array.
     */
    public function offsetExists($offset): bool
    {
        return isset($this->data[$offset]);
    }
    /**
     * Get an offset from the data array.
     */
    public function offsetGet($offset): mixed
    {
        return $this->data[$offset] ?? null;
    }
    /**
     * Set an offset in the data array.
     */
    public function offsetSet($offset, $value): void
    {
        if ($offset === null) {
            $this->data[] = $value;
        } else {
            $this->data[$offset] = $value;
        }
    }
    /**
     * Unset an offset in the data array.
     */
    public function offsetUnset($offset): void
    {
        unset($this->data[$offset]);
    }
    /**
     * Get the city ID.
     */
    public function getId(): ?int
    {
        return $this->get('id');
    }
    /**
     * Get the city name.
     */
    public function getName(): ?string
    {
        return $this->get('name');
    }
    /**
     * Get the city latitude.
     */
    public function getLatitude(): ?string
    {
        return $this->get('latitude');
    }
    /**
     * Get the city longitude.
     */
    public function getLongitude(): ?string
    {
        return $this->get('longitude');
    }
}
 |