mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 17:23:12 +08:00
Used ShlinkTable on every location rendering a CLI table
This commit is contained in:
@@ -11,6 +11,8 @@ use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||
|
||||
/**
|
||||
* Class Visit
|
||||
@@ -88,9 +90,9 @@ class Visit extends AbstractEntity implements JsonSerializable
|
||||
return ! empty($this->remoteAddr);
|
||||
}
|
||||
|
||||
public function getVisitLocation(): VisitLocation
|
||||
public function getVisitLocation(): VisitLocationInterface
|
||||
{
|
||||
return $this->visitLocation;
|
||||
return $this->visitLocation ?? new UnknownVisitLocation();
|
||||
}
|
||||
|
||||
public function locate(VisitLocation $visitLocation): self
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ use function array_key_exists;
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="visit_locations")
|
||||
*/
|
||||
class VisitLocation extends AbstractEntity implements JsonSerializable
|
||||
class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
||||
47
module/Core/src/Visit/Model/UnknownVisitLocation.php
Normal file
47
module/Core/src/Visit/Model/UnknownVisitLocation.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Model;
|
||||
|
||||
final class UnknownVisitLocation implements VisitLocationInterface
|
||||
{
|
||||
public function getCountryName(): string
|
||||
{
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
public function getLatitude(): string
|
||||
{
|
||||
return '0.0';
|
||||
}
|
||||
|
||||
public function getLongitude(): string
|
||||
{
|
||||
return '0.0';
|
||||
}
|
||||
|
||||
public function getCityName(): string
|
||||
{
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'countryCode' => 'Unknown',
|
||||
'countryName' => 'Unknown',
|
||||
'regionName' => 'Unknown',
|
||||
'cityName' => 'Unknown',
|
||||
'latitude' => '0.0',
|
||||
'longitude' => '0.0',
|
||||
'timezone' => 'Unknown',
|
||||
];
|
||||
}
|
||||
}
|
||||
17
module/Core/src/Visit/Model/VisitLocationInterface.php
Normal file
17
module/Core/src/Visit/Model/VisitLocationInterface.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
interface VisitLocationInterface extends JsonSerializable
|
||||
{
|
||||
public function getCountryName(): string;
|
||||
|
||||
public function getLatitude(): string;
|
||||
|
||||
public function getLongitude(): string;
|
||||
|
||||
public function getCityName(): string;
|
||||
}
|
||||
Reference in New Issue
Block a user