Moved Ip resolvers to the Resolver subnamespace

This commit is contained in:
Alejandro Celaya 2019-08-10 13:56:06 +02:00
parent 30314fd532
commit 3520ab6b18
16 changed files with 42 additions and 31 deletions

View File

@ -10,7 +10,7 @@ use Shlinkio\Shlink\Common\Doctrine\NoDbNameConnectionFactory;
use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Shlinkio\Shlink\Common\Service\PreviewGenerator;
use Shlinkio\Shlink\Core\Service; use Shlinkio\Shlink\Core\Service;
use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater; use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater;
use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use Symfony\Component\Console as SymfonyCli; use Symfony\Component\Console as SymfonyCli;
use Symfony\Component\Lock\Factory as Locker; use Symfony\Component\Lock\Factory as Locker;

View File

@ -15,8 +15,8 @@ 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\IpLocationResolverInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;

View File

@ -16,8 +16,8 @@ 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\IpApiLocationResolver;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpApiLocationResolver;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core; namespace Shlinkio\Shlink\Core;
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater;
use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
return [ return [

View File

@ -10,8 +10,8 @@ use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface;
use Shlinkio\Shlink\Common\Exception\WrongIpException; 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\IpLocationResolverInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use function sprintf; use function sprintf;

View File

@ -19,8 +19,8 @@ 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\IpLocationResolverInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
class LocateShortUrlVisitTest extends TestCase class LocateShortUrlVisitTest extends TestCase
{ {

View File

@ -13,26 +13,28 @@ return [
'dependencies' => [ 'dependencies' => [
'factories' => [ 'factories' => [
IpApiLocationResolver::class => ConfigAbstractFactory::class, Resolver\IpApiLocationResolver::class => ConfigAbstractFactory::class,
GeoLite2LocationResolver::class => ConfigAbstractFactory::class, Resolver\GeoLite2LocationResolver::class => ConfigAbstractFactory::class,
EmptyIpLocationResolver::class => InvokableFactory::class, Resolver\EmptyIpLocationResolver::class => InvokableFactory::class,
ChainIpLocationResolver::class => ConfigAbstractFactory::class, Resolver\ChainIpLocationResolver::class => ConfigAbstractFactory::class,
GeoLite2\GeoLite2Options::class => ConfigAbstractFactory::class, GeoLite2\GeoLite2Options::class => ConfigAbstractFactory::class,
GeoLite2\DbUpdater::class => ConfigAbstractFactory::class, GeoLite2\DbUpdater::class => ConfigAbstractFactory::class,
], ],
'aliases' => [ 'aliases' => [
IpLocationResolverInterface::class => ChainIpLocationResolver::class, Resolver\IpLocationResolverInterface::class => Resolver\ChainIpLocationResolver::class,
], ],
], ],
ConfigAbstractFactory::class => [ ConfigAbstractFactory::class => [
IpApiLocationResolver::class => ['httpClient'], Resolver\IpApiLocationResolver::class => [GuzzleClient::class],
GeoLite2LocationResolver::class => [Reader::class], Resolver\GeoLite2LocationResolver::class => [Reader::class],
ChainIpLocationResolver::class => [ Resolver\ChainIpLocationResolver::class => [
GeoLite2LocationResolver::class, Resolver\GeoLite2LocationResolver::class,
IpApiLocationResolver::class, Resolver\IpApiLocationResolver::class,
EmptyIpLocationResolver::class, Resolver\EmptyIpLocationResolver::class,
], ],
GeoLite2\GeoLite2Options::class => ['config.geolite2'], GeoLite2\GeoLite2Options::class => ['config.geolite2'],
GeoLite2\DbUpdater::class => [ GeoLite2\DbUpdater::class => [
GuzzleClient::class, GuzzleClient::class,

View File

@ -1,9 +1,11 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shlinkio\Shlink\IpGeolocation; namespace Shlinkio\Shlink\IpGeolocation\Resolver;
use Shlinkio\Shlink\Common\Exception\WrongIpException; use Shlinkio\Shlink\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
class ChainIpLocationResolver implements IpLocationResolverInterface class ChainIpLocationResolver implements IpLocationResolverInterface
{ {

View File

@ -1,9 +1,11 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shlinkio\Shlink\IpGeolocation; namespace Shlinkio\Shlink\IpGeolocation\Resolver;
use Shlinkio\Shlink\Common\Exception\WrongIpException; use Shlinkio\Shlink\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
class EmptyIpLocationResolver implements IpLocationResolverInterface class EmptyIpLocationResolver implements IpLocationResolverInterface
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shlinkio\Shlink\IpGeolocation; namespace Shlinkio\Shlink\IpGeolocation\Resolver;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException; use GeoIp2\Exception\AddressNotFoundException;
@ -9,6 +9,8 @@ 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\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use function Functional\first; use function Functional\first;

View File

@ -1,12 +1,14 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shlinkio\Shlink\IpGeolocation; 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\Common\Exception\WrongIpException;
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;

View File

@ -1,9 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shlinkio\Shlink\IpGeolocation; namespace Shlinkio\Shlink\IpGeolocation\Resolver;
use Shlinkio\Shlink\Common\Exception\WrongIpException; use Shlinkio\Shlink\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model;
interface IpLocationResolverInterface interface IpLocationResolverInterface
{ {

View File

@ -1,14 +1,14 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace ShlinkioTest\Shlink\IpGeolocation; 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\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\ChainIpLocationResolver;
use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\ChainIpLocationResolver;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
class ChainIpLocationResolverTest extends TestCase class ChainIpLocationResolverTest extends TestCase
{ {

View File

@ -1,12 +1,12 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace ShlinkioTest\Shlink\IpGeolocation; namespace ShlinkioTest\Shlink\IpGeolocation\Resolver;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Util\StringUtilsTrait; use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
use Shlinkio\Shlink\IpGeolocation\EmptyIpLocationResolver;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\EmptyIpLocationResolver;
use function Functional\map; use function Functional\map;
use function range; use function range;

View File

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace ShlinkioTest\Shlink\IpGeolocation; namespace ShlinkioTest\Shlink\IpGeolocation\Resolver;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException; use GeoIp2\Exception\AddressNotFoundException;
@ -10,8 +10,8 @@ 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\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\GeoLite2LocationResolver;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\GeoLite2LocationResolver;
class GeoLite2LocationResolverTest extends TestCase class GeoLite2LocationResolverTest extends TestCase
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace ShlinkioTest\Shlink\IpGeolocation; namespace ShlinkioTest\Shlink\IpGeolocation\Resolver;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Exception\TransferException;
@ -9,8 +9,8 @@ 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\Common\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\IpApiLocationResolver;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpApiLocationResolver;
use function json_encode; use function json_encode;