mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-07 07:43:12 +08:00
Defined stricter model to represent one geo location
This commit is contained in:
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\Entity;
|
||||
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Common\IpGeolocation\Model\Location;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
||||
{
|
||||
@@ -24,9 +24,9 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
||||
/** @var string */
|
||||
private $timezone;
|
||||
|
||||
public function __construct(array $locationInfo)
|
||||
public function __construct(Location $location)
|
||||
{
|
||||
$this->exchangeArray($locationInfo);
|
||||
$this->exchangeLocationInfo($location);
|
||||
}
|
||||
|
||||
public function getCountryName(): string
|
||||
@@ -49,32 +49,15 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
||||
return $this->cityName ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange internal values from provided array
|
||||
*/
|
||||
private function exchangeArray(array $array): void
|
||||
private function exchangeLocationInfo(Location $info): void
|
||||
{
|
||||
if (array_key_exists('country_code', $array)) {
|
||||
$this->countryCode = (string) $array['country_code'];
|
||||
}
|
||||
if (array_key_exists('country_name', $array)) {
|
||||
$this->countryName = (string) $array['country_name'];
|
||||
}
|
||||
if (array_key_exists('region_name', $array)) {
|
||||
$this->regionName = (string) $array['region_name'];
|
||||
}
|
||||
if (array_key_exists('city', $array)) {
|
||||
$this->cityName = (string) $array['city'];
|
||||
}
|
||||
if (array_key_exists('latitude', $array)) {
|
||||
$this->latitude = (string) $array['latitude'];
|
||||
}
|
||||
if (array_key_exists('longitude', $array)) {
|
||||
$this->longitude = (string) $array['longitude'];
|
||||
}
|
||||
if (array_key_exists('time_zone', $array)) {
|
||||
$this->timezone = (string) $array['time_zone'];
|
||||
}
|
||||
$this->countryCode = $info->countryCode();
|
||||
$this->countryName = $info->countryName();
|
||||
$this->regionName = $info->regionName();
|
||||
$this->cityName = $info->city();
|
||||
$this->latitude = (string) $info->latitude();
|
||||
$this->longitude = (string) $info->longitude();
|
||||
$this->timezone = $info->timeZone();
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
|
||||
Reference in New Issue
Block a user