__("United Kingdom"), "AU" => __("Australia"), "BG" => __("Bulgaria"), "CA" => __("Canada"), "CN" => __("China"), "CZ" => __("Czech Republic"), "DK" => __("Denmark"), "FR" => __("France"), "DE" => __("Germany"), "HK" => __("Hong Kong"), "IT" => __("Italy"), "JP" => __("Japan"), "NZ" => __("New Zealand"), "NO" => __("Norway"), "PL" => __("Poland"), "ES" => __("Spain"), "SE" => __("Sweden"), "CH" => __("Switzerland"), "US" => __("United States"), ]; } // Magic methods public function __toString(): string { return implode("\n", $this->getLines()); } // Object methods public function hasGeolocation(): bool { return isset($this->latitude, $this->longitude); } public function geocode(): ?array { try { $results = Geolocation::geocode($this->postal_code); $result = $results[0]; $this->latitude = $result->geometry->location->lat; $this->longitude = $result->geometry->location->lng; return [$this->latitude, $this->longitude]; } catch(Exception $e) { return null; } } private function getDisplayCountry(): string { if($this->country) { return self::getCountryOptions()[$this->country] ?? ""; } return ""; } public function getLines(): array { $county_parts = array_filter([$this->county, $this->state, $this->postal_code]); return array_values(array_filter([ $this->address_1, $this->address_2, $this->city, implode(", ", $county_parts), $this->getDisplayCountry() ])); } public function getLinesHtml(): string { return nl2br(htmlspecialchars(implode("\n", $this->getLines()))); } }