mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Moved WrongIpException to IpGeolocation module
This commit is contained in:
@@ -7,8 +7,8 @@ use Doctrine\DBAL\DBALException;
|
|||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
use PDO;
|
use PDO;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto-generated Migration: Please modify to your needs!
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig;
|
|||||||
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
||||||
use Shlinkio\Shlink\CLI\Util\ExitCodes;
|
use Shlinkio\Shlink\CLI\Util\ExitCodes;
|
||||||
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||||
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
||||||
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
|
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
|
||||||
use Shlinkio\Shlink\Core\Service\VisitServiceInterface;
|
use Shlinkio\Shlink\Core\Service\VisitServiceInterface;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ use Prophecy\Prophecy\ObjectProphecy;
|
|||||||
use Shlinkio\Shlink\CLI\Command\Visit\LocateVisitsCommand;
|
use Shlinkio\Shlink\CLI\Command\Visit\LocateVisitsCommand;
|
||||||
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
||||||
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||||
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
||||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||||
use Shlinkio\Shlink\Core\Service\VisitService;
|
use Shlinkio\Shlink\Core\Service\VisitService;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpApiLocationResolver;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpApiLocationResolver;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Common\Util;
|
namespace Shlinkio\Shlink\Common\Util;
|
||||||
|
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
|
|
||||||
use function count;
|
use function count;
|
||||||
use function explode;
|
use function explode;
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ namespace Shlinkio\Shlink\Core\Entity;
|
|||||||
use Cake\Chronos\Chronos;
|
use Cake\Chronos\Chronos;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||||
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
||||||
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
|
|
||||||
class Visit extends AbstractEntity implements JsonSerializable
|
class Visit extends AbstractEntity implements JsonSerializable
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
||||||
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||||
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ use Prophecy\Prophecy\ObjectProphecy;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
||||||
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||||
@@ -19,6 +18,7 @@ use Shlinkio\Shlink\Core\EventDispatcher\LocateShortUrlVisit;
|
|||||||
use Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited;
|
use Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited;
|
||||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||||
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
||||||
|
|
||||||
|
|||||||
10
module/IpGeolocation/src/Exception/ExceptionInterface.php
Normal file
10
module/IpGeolocation/src/Exception/ExceptionInterface.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\IpGeolocation\Exception;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
interface ExceptionInterface extends Throwable
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\Common\Exception;
|
namespace Shlinkio\Shlink\IpGeolocation\Exception;
|
||||||
|
|
||||||
|
use Shlinkio\Shlink\Common\Exception\RuntimeException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
class WrongIpException extends RuntimeException
|
class WrongIpException extends RuntimeException implements ExceptionInterface
|
||||||
{
|
{
|
||||||
public static function fromIpAddress($ipAddress, ?Throwable $prev = null): self
|
public static function fromIpAddress($ipAddress, ?Throwable $prev = null): self
|
||||||
{
|
{
|
||||||
@@ -3,9 +3,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
||||||
|
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model;
|
use Shlinkio\Shlink\IpGeolocation\Model;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
|
||||||
|
|
||||||
class ChainIpLocationResolver implements IpLocationResolverInterface
|
class ChainIpLocationResolver implements IpLocationResolverInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
||||||
|
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model;
|
use Shlinkio\Shlink\IpGeolocation\Model;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
|
||||||
|
|
||||||
class EmptyIpLocationResolver implements IpLocationResolverInterface
|
class EmptyIpLocationResolver implements IpLocationResolverInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ use GeoIp2\Exception\AddressNotFoundException;
|
|||||||
use GeoIp2\Model\City;
|
use GeoIp2\Model\City;
|
||||||
use GeoIp2\Record\Subdivision;
|
use GeoIp2\Record\Subdivision;
|
||||||
use MaxMind\Db\Reader\InvalidDatabaseException;
|
use MaxMind\Db\Reader\InvalidDatabaseException;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model;
|
use Shlinkio\Shlink\IpGeolocation\Model;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
|
||||||
|
|
||||||
use function Functional\first;
|
use function Functional\first;
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
|||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model;
|
use Shlinkio\Shlink\IpGeolocation\Model;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
|
||||||
|
|
||||||
use function Shlinkio\Shlink\Common\json_decode;
|
use function Shlinkio\Shlink\Common\json_decode;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
namespace Shlinkio\Shlink\IpGeolocation\Resolver;
|
||||||
|
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model;
|
use Shlinkio\Shlink\IpGeolocation\Model;
|
||||||
|
|
||||||
interface IpLocationResolverInterface
|
interface IpLocationResolverInterface
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common\Exception;
|
namespace ShlinkioTest\Shlink\IpGeolocation\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
|
|
||||||
class WrongIpExceptionTest extends TestCase
|
class WrongIpExceptionTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @test */
|
/** @test */
|
||||||
public function fromIpAddressProperlyCreatesExceptionWithoutPrev()
|
public function fromIpAddressProperlyCreatesExceptionWithoutPrev(): void
|
||||||
{
|
{
|
||||||
$e = WrongIpException::fromIpAddress('1.2.3.4');
|
$e = WrongIpException::fromIpAddress('1.2.3.4');
|
||||||
|
|
||||||
@@ -18,8 +18,9 @@ class WrongIpExceptionTest extends TestCase
|
|||||||
$this->assertEquals(0, $e->getCode());
|
$this->assertEquals(0, $e->getCode());
|
||||||
$this->assertNull($e->getPrevious());
|
$this->assertNull($e->getPrevious());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function fromIpAddressProperlyCreatesExceptionWithPrev()
|
public function fromIpAddressProperlyCreatesExceptionWithPrev(): void
|
||||||
{
|
{
|
||||||
$prev = new Exception('Previous error');
|
$prev = new Exception('Previous error');
|
||||||
$e = WrongIpException::fromIpAddress('1.2.3.4', $prev);
|
$e = WrongIpException::fromIpAddress('1.2.3.4', $prev);
|
||||||
@@ -5,7 +5,7 @@ namespace ShlinkioTest\Shlink\IpGeolocation\Resolver;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\ChainIpLocationResolver;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\ChainIpLocationResolver;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use GeoIp2\Model\City;
|
|||||||
use MaxMind\Db\Reader\InvalidDatabaseException;
|
use MaxMind\Db\Reader\InvalidDatabaseException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\GeoLite2LocationResolver;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\GeoLite2LocationResolver;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use GuzzleHttp\Exception\TransferException;
|
|||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||||
use Shlinkio\Shlink\IpGeolocation\Resolver\IpApiLocationResolver;
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpApiLocationResolver;
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ namespace ShlinkioTest\Shlink\Rest\Util;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
|
||||||
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
|
||||||
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
||||||
|
use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
|
||||||
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
||||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user