1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Shlinkio\Shlink\Core\Entity; |
6
|
|
|
|
7
|
|
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity; |
8
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface; |
9
|
|
|
use Shlinkio\Shlink\IpGeolocation\Model\Location; |
10
|
|
|
|
11
|
|
|
class VisitLocation extends AbstractEntity implements VisitLocationInterface |
12
|
|
|
{ |
13
|
|
|
private string $countryCode; |
14
|
|
|
private string $countryName; |
15
|
|
|
private string $regionName; |
16
|
|
|
private string $cityName; |
17
|
|
|
private float $latitude; |
18
|
|
|
private float $longitude; |
19
|
|
|
private string $timezone; |
20
|
|
|
|
21
|
21 |
|
public function __construct(Location $location) |
22
|
|
|
{ |
23
|
21 |
|
$this->exchangeLocationInfo($location); |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
public function getCountryName(): string |
27
|
|
|
{ |
28
|
1 |
|
return $this->countryName; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getLatitude(): float |
32
|
|
|
{ |
33
|
|
|
return $this->latitude; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getLongitude(): float |
37
|
|
|
{ |
38
|
|
|
return $this->longitude; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getCityName(): string |
42
|
|
|
{ |
43
|
|
|
return $this->cityName; |
44
|
|
|
} |
45
|
|
|
|
46
|
21 |
|
private function exchangeLocationInfo(Location $info): void |
47
|
|
|
{ |
48
|
21 |
|
$this->countryCode = $info->countryCode(); |
49
|
21 |
|
$this->countryName = $info->countryName(); |
50
|
21 |
|
$this->regionName = $info->regionName(); |
51
|
21 |
|
$this->cityName = $info->city(); |
52
|
21 |
|
$this->latitude = $info->latitude(); |
53
|
21 |
|
$this->longitude = $info->longitude(); |
54
|
21 |
|
$this->timezone = $info->timeZone(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function jsonSerialize(): array |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'countryCode' => $this->countryCode, |
61
|
|
|
'countryName' => $this->countryName, |
62
|
|
|
'regionName' => $this->regionName, |
63
|
|
|
'cityName' => $this->cityName, |
64
|
|
|
'latitude' => $this->latitude, |
65
|
|
|
'longitude' => $this->longitude, |
66
|
|
|
'timezone' => $this->timezone, |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
9 |
|
public function isEmpty(): bool |
71
|
|
|
{ |
72
|
|
|
return |
73
|
9 |
|
$this->countryCode === '' && |
74
|
9 |
|
$this->countryName === '' && |
75
|
9 |
|
$this->regionName === '' && |
76
|
9 |
|
$this->cityName === '' && |
77
|
9 |
|
$this->latitude === 0.0 && |
78
|
9 |
|
$this->longitude === 0.0 && |
79
|
9 |
|
$this->timezone === ''; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|