2016-07-20 10:35:46 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-20 10:35:46 +03:00
|
|
|
namespace Shlinkio\Shlink\Core\Entity;
|
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
2018-12-08 14:12:11 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
2019-08-10 14:42:37 +03:00
|
|
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
2016-07-20 10:35:46 +03:00
|
|
|
|
2018-12-08 14:12:11 +03:00
|
|
|
class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2019-12-30 00:27:00 +03:00
|
|
|
private string $countryCode;
|
|
|
|
private string $countryName;
|
|
|
|
private string $regionName;
|
|
|
|
private string $cityName;
|
2020-01-01 01:37:49 +03:00
|
|
|
private float $latitude;
|
|
|
|
private float $longitude;
|
2019-12-30 00:27:00 +03:00
|
|
|
private string $timezone;
|
2020-03-23 22:37:45 +03:00
|
|
|
private bool $isEmpty;
|
2016-07-20 10:35:46 +03:00
|
|
|
|
2019-02-17 14:59:55 +03:00
|
|
|
public function __construct(Location $location)
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2019-02-17 14:59:55 +03:00
|
|
|
$this->exchangeLocationInfo($location);
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-15 11:03:42 +03:00
|
|
|
public function getCountryName(): string
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2020-01-01 01:37:49 +03:00
|
|
|
return $this->countryName;
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2020-01-01 01:37:49 +03:00
|
|
|
public function getLatitude(): float
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2020-01-01 01:37:49 +03:00
|
|
|
return $this->latitude;
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2020-01-01 01:37:49 +03:00
|
|
|
public function getLongitude(): float
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2020-01-01 01:37:49 +03:00
|
|
|
return $this->longitude;
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-10-28 17:13:45 +03:00
|
|
|
public function getCityName(): string
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2020-01-01 01:37:49 +03:00
|
|
|
return $this->cityName;
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2020-03-23 22:37:45 +03:00
|
|
|
public function isEmpty(): bool
|
|
|
|
{
|
|
|
|
return $this->isEmpty;
|
|
|
|
}
|
|
|
|
|
2019-02-17 14:59:55 +03:00
|
|
|
private function exchangeLocationInfo(Location $info): void
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2019-02-17 14:59:55 +03:00
|
|
|
$this->countryCode = $info->countryCode();
|
|
|
|
$this->countryName = $info->countryName();
|
|
|
|
$this->regionName = $info->regionName();
|
|
|
|
$this->cityName = $info->city();
|
2020-01-01 01:37:49 +03:00
|
|
|
$this->latitude = $info->latitude();
|
|
|
|
$this->longitude = $info->longitude();
|
2019-02-17 14:59:55 +03:00
|
|
|
$this->timezone = $info->timeZone();
|
2020-03-23 22:37:45 +03:00
|
|
|
$this->isEmpty = (
|
|
|
|
$this->countryCode === '' &&
|
|
|
|
$this->countryName === '' &&
|
|
|
|
$this->regionName === '' &&
|
|
|
|
$this->cityName === '' &&
|
|
|
|
$this->latitude === 0.0 &&
|
|
|
|
$this->longitude === 0.0 &&
|
|
|
|
$this->timezone === ''
|
|
|
|
);
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-10-28 17:13:45 +03:00
|
|
|
public function jsonSerialize(): array
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'countryCode' => $this->countryCode,
|
|
|
|
'countryName' => $this->countryName,
|
|
|
|
'regionName' => $this->regionName,
|
|
|
|
'cityName' => $this->cityName,
|
|
|
|
'latitude' => $this->latitude,
|
|
|
|
'longitude' => $this->longitude,
|
|
|
|
'timezone' => $this->timezone,
|
2020-03-23 22:37:45 +03:00
|
|
|
'isEmpty' => $this->isEmpty,
|
2016-07-20 10:35:46 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|