|
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
|
|
|
private bool $isEmpty; |
|
21
|
|
|
|
|
22
|
28 |
|
public function __construct(Location $location) |
|
23
|
|
|
{ |
|
24
|
28 |
|
$this->exchangeLocationInfo($location); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function getCountryName(): string |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->countryName; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getLatitude(): float |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->latitude; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getLongitude(): float |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->longitude; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getCityName(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->cityName; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
11 |
|
public function isEmpty(): bool |
|
48
|
|
|
{ |
|
49
|
11 |
|
return $this->isEmpty; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
28 |
|
private function exchangeLocationInfo(Location $info): void |
|
53
|
|
|
{ |
|
54
|
28 |
|
$this->countryCode = $info->countryCode(); |
|
55
|
28 |
|
$this->countryName = $info->countryName(); |
|
56
|
28 |
|
$this->regionName = $info->regionName(); |
|
57
|
28 |
|
$this->cityName = $info->city(); |
|
58
|
28 |
|
$this->latitude = $info->latitude(); |
|
59
|
28 |
|
$this->longitude = $info->longitude(); |
|
60
|
28 |
|
$this->timezone = $info->timeZone(); |
|
61
|
28 |
|
$this->isEmpty = ( |
|
62
|
28 |
|
$this->countryCode === '' && |
|
63
|
28 |
|
$this->countryName === '' && |
|
64
|
28 |
|
$this->regionName === '' && |
|
65
|
28 |
|
$this->cityName === '' && |
|
66
|
28 |
|
$this->latitude === 0.0 && |
|
|
|
|
|
|
67
|
28 |
|
$this->longitude === 0.0 && |
|
68
|
21 |
|
$this->timezone === '' |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function jsonSerialize(): array |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
|
|
'countryCode' => $this->countryCode, |
|
76
|
|
|
'countryName' => $this->countryName, |
|
77
|
|
|
'regionName' => $this->regionName, |
|
78
|
|
|
'cityName' => $this->cityName, |
|
79
|
|
|
'latitude' => $this->latitude, |
|
80
|
|
|
'longitude' => $this->longitude, |
|
81
|
|
|
'timezone' => $this->timezone, |
|
82
|
|
|
'isEmpty' => $this->isEmpty, |
|
83
|
|
|
]; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|