diff --git a/composer.json b/composer.json index 89d25ece..bedf3f9a 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,8 @@ "Shlinkio\\Shlink\\Rest\\": "module/Rest/src", "Shlinkio\\Shlink\\Core\\": "module/Core/src", "Shlinkio\\Shlink\\Common\\": "module/Common/src", - "Shlinkio\\Shlink\\EventDispatcher\\": "module/EventDispatcher/src" + "Shlinkio\\Shlink\\EventDispatcher\\": "module/EventDispatcher/src", + "Shlinkio\\Shlink\\IpGeolocation\\": "module/IpGeolocation/src/" }, "files": [ "module/Common/functions/functions.php", @@ -94,7 +95,8 @@ "module/Common/test", "module/Common/test-db" ], - "ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test" + "ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test", + "ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test" } }, "scripts": { diff --git a/config/config.php b/config/config.php index 2c29fe67..d5776eef 100644 --- a/config/config.php +++ b/config/config.php @@ -17,6 +17,7 @@ return (new ConfigAggregator\ConfigAggregator([ Expressive\Swoole\ConfigProvider::class, ExpressiveErrorHandler\ConfigProvider::class, Common\ConfigProvider::class, + IpGeolocation\ConfigProvider::class, Core\ConfigProvider::class, CLI\ConfigProvider::class, Rest\ConfigProvider::class, diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index 10870e08..ee4c8952 100644 --- a/module/CLI/config/dependencies.config.php +++ b/module/CLI/config/dependencies.config.php @@ -7,10 +7,10 @@ use Doctrine\DBAL\Connection; use GeoIp2\Database\Reader; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater; use Shlinkio\Shlink\Common\Doctrine\NoDbNameConnectionFactory; -use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdater; -use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface; use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Shlinkio\Shlink\Core\Service; +use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater; +use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Symfony\Component\Console as SymfonyCli; use Symfony\Component\Lock\Factory as Locker; diff --git a/module/CLI/src/Command/Visit/LocateVisitsCommand.php b/module/CLI/src/Command/Visit/LocateVisitsCommand.php index 857028c3..d337d1fb 100644 --- a/module/CLI/src/Command/Visit/LocateVisitsCommand.php +++ b/module/CLI/src/Command/Visit/LocateVisitsCommand.php @@ -10,13 +10,13 @@ use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Common\Exception\WrongIpException; -use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Common\Util\IpAddress; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; use Shlinkio\Shlink\Core\Service\VisitServiceInterface; +use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; +use Shlinkio\Shlink\IpGeolocation\Model\Location; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/module/CLI/src/Command/Visit/UpdateDbCommand.php b/module/CLI/src/Command/Visit/UpdateDbCommand.php index 3882b2c6..938c24b7 100644 --- a/module/CLI/src/Command/Visit/UpdateDbCommand.php +++ b/module/CLI/src/Command/Visit/UpdateDbCommand.php @@ -5,7 +5,7 @@ namespace Shlinkio\Shlink\CLI\Command\Visit; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\Common\Exception\RuntimeException; -use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdaterInterface; +use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; diff --git a/module/CLI/src/Util/GeolocationDbUpdater.php b/module/CLI/src/Util/GeolocationDbUpdater.php index e7ea60b9..48f958ca 100644 --- a/module/CLI/src/Util/GeolocationDbUpdater.php +++ b/module/CLI/src/Util/GeolocationDbUpdater.php @@ -7,7 +7,7 @@ use Cake\Chronos\Chronos; use GeoIp2\Database\Reader; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\Common\Exception\RuntimeException; -use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdaterInterface; +use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface; use Symfony\Component\Lock\Factory as Locker; use Throwable; diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index 3e553bbc..620b2963 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\GetVisitsCommand; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; @@ -16,6 +15,7 @@ use Shlinkio\Shlink\Core\Entity\VisitLocation; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; +use Shlinkio\Shlink\IpGeolocation\Model\Location; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Zend\Paginator\Adapter\ArrayAdapter; diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index e0bace38..543c619d 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -10,14 +10,14 @@ use Shlinkio\Shlink\CLI\Command\Visit\LocateVisitsCommand; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Common\Exception\WrongIpException; -use Shlinkio\Shlink\Common\IpGeolocation\IpApiLocationResolver; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Common\Util\IpAddress; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Service\VisitService; +use Shlinkio\Shlink\IpGeolocation\IpApiLocationResolver; +use Shlinkio\Shlink\IpGeolocation\Model\Location; use Symfony\Component\Console\Application; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; diff --git a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php index 63f87b6d..ea4e0861 100644 --- a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php +++ b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php @@ -9,7 +9,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Visit\UpdateDbCommand; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\Common\Exception\RuntimeException; -use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdaterInterface; +use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; diff --git a/module/CLI/test/Util/GeolocationDbUpdaterTest.php b/module/CLI/test/Util/GeolocationDbUpdaterTest.php index 6dd11807..137e70de 100644 --- a/module/CLI/test/Util/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/Util/GeolocationDbUpdaterTest.php @@ -12,7 +12,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater; use Shlinkio\Shlink\Common\Exception\RuntimeException; -use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdaterInterface; +use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface; use Symfony\Component\Lock; use Throwable; diff --git a/module/Common/config/dependencies.config.php b/module/Common/config/dependencies.config.php index f5c79b05..34e37d6e 100644 --- a/module/Common/config/dependencies.config.php +++ b/module/Common/config/dependencies.config.php @@ -31,13 +31,6 @@ return [ Image\ImageBuilder::class => Image\ImageBuilderFactory::class, - IpGeolocation\IpApiLocationResolver::class => ConfigAbstractFactory::class, - IpGeolocation\GeoLite2LocationResolver::class => ConfigAbstractFactory::class, - IpGeolocation\EmptyIpLocationResolver::class => InvokableFactory::class, - IpGeolocation\ChainIpLocationResolver::class => ConfigAbstractFactory::class, - IpGeolocation\GeoLite2\GeoLite2Options::class => ConfigAbstractFactory::class, - IpGeolocation\GeoLite2\DbUpdater::class => ConfigAbstractFactory::class, - Service\PreviewGenerator::class => ConfigAbstractFactory::class, ], 'aliases' => [ @@ -47,8 +40,6 @@ return [ 'logger' => LoggerInterface::class, Logger::class => 'Logger_Shlink', LoggerInterface::class => 'Logger_Shlink', - - IpGeolocation\IpLocationResolverInterface::class => IpGeolocation\ChainIpLocationResolver::class, ], 'abstract_factories' => [ Factory\DottedAccessConfigAbstractFactory::class, @@ -75,20 +66,6 @@ return [ Middleware\LocaleMiddleware::class => ['translator'], Middleware\CloseDbConnectionMiddleware::class => ['em'], - IpGeolocation\IpApiLocationResolver::class => ['httpClient'], - IpGeolocation\GeoLite2LocationResolver::class => [Reader::class], - IpGeolocation\ChainIpLocationResolver::class => [ - IpGeolocation\GeoLite2LocationResolver::class, - IpGeolocation\IpApiLocationResolver::class, - IpGeolocation\EmptyIpLocationResolver::class, - ], - IpGeolocation\GeoLite2\GeoLite2Options::class => ['config.geolite2'], - IpGeolocation\GeoLite2\DbUpdater::class => [ - GuzzleClient::class, - Filesystem::class, - IpGeolocation\GeoLite2\GeoLite2Options::class, - ], - Service\PreviewGenerator::class => [ Image\ImageBuilder::class, Filesystem::class, diff --git a/module/Common/src/ConfigProvider.php b/module/Common/src/ConfigProvider.php index b6f3566a..0d0c8a0d 100644 --- a/module/Common/src/ConfigProvider.php +++ b/module/Common/src/ConfigProvider.php @@ -8,7 +8,7 @@ use Zend\Stdlib\Glob; class ConfigProvider { - public function __invoke() + public function __invoke(): array { return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE)); } diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index 767142f1..c47114d2 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater; -use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface; +use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; return [ diff --git a/module/Core/src/Entity/VisitLocation.php b/module/Core/src/Entity/VisitLocation.php index fad9c986..76899597 100644 --- a/module/Core/src/Entity/VisitLocation.php +++ b/module/Core/src/Entity/VisitLocation.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Entity; use Shlinkio\Shlink\Common\Entity\AbstractEntity; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface; +use Shlinkio\Shlink\IpGeolocation\Model\Location; class VisitLocation extends AbstractEntity implements VisitLocationInterface { diff --git a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php index de7eb360..528ccbf5 100644 --- a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php +++ b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php @@ -8,10 +8,10 @@ use Psr\Log\LoggerInterface; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Common\Exception\WrongIpException; -use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; +use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; +use Shlinkio\Shlink\IpGeolocation\Model\Location; use function sprintf; diff --git a/module/Core/src/Service/VisitService.php b/module/Core/src/Service/VisitService.php index dc3a11c9..f0a59c03 100644 --- a/module/Core/src/Service/VisitService.php +++ b/module/Core/src/Service/VisitService.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service; use Doctrine\ORM\EntityManagerInterface; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; use Shlinkio\Shlink\Core\Repository\VisitRepository; +use Shlinkio\Shlink\IpGeolocation\Model\Location; class VisitService implements VisitServiceInterface { diff --git a/module/Core/test-db/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php index 871c7aed..3b0e758a 100644 --- a/module/Core/test-db/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Repository/VisitRepositoryTest.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Core\Repository; use Cake\Chronos\Chronos; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Repository\VisitRepository; +use Shlinkio\Shlink\IpGeolocation\Model\Location; use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase; use function Functional\map; diff --git a/module/Core/test/Entity/VisitLocationTest.php b/module/Core/test/Entity/VisitLocationTest.php index d331d5c6..fb210226 100644 --- a/module/Core/test/Entity/VisitLocationTest.php +++ b/module/Core/test/Entity/VisitLocationTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Core\Entity; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Core\Entity\VisitLocation; +use Shlinkio\Shlink\IpGeolocation\Model\Location; class VisitLocationTest extends TestCase { diff --git a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php index ced0bd63..4f76ca98 100644 --- a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php @@ -11,8 +11,6 @@ use Psr\Log\LoggerInterface; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Common\Exception\WrongIpException; -use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Common\Util\IpAddress; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; @@ -21,6 +19,8 @@ use Shlinkio\Shlink\Core\EventDispatcher\LocateShortUrlVisit; use Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation; +use Shlinkio\Shlink\IpGeolocation\IpLocationResolverInterface; +use Shlinkio\Shlink\IpGeolocation\Model\Location; class LocateShortUrlVisitTest extends TestCase { diff --git a/module/Core/test/Service/VisitServiceTest.php b/module/Core/test/Service/VisitServiceTest.php index 85f29ee4..37d360c5 100644 --- a/module/Core/test/Service/VisitServiceTest.php +++ b/module/Core/test/Service/VisitServiceTest.php @@ -7,7 +7,6 @@ use Doctrine\ORM\EntityManager; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; -use Shlinkio\Shlink\Common\IpGeolocation\Model\Location; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; @@ -15,6 +14,7 @@ use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Repository\VisitRepository; use Shlinkio\Shlink\Core\Service\VisitService; +use Shlinkio\Shlink\IpGeolocation\Model\Location; use function array_shift; use function count; diff --git a/module/IpGeolocation/config/dependencies.config.php b/module/IpGeolocation/config/dependencies.config.php new file mode 100644 index 00000000..a42bad67 --- /dev/null +++ b/module/IpGeolocation/config/dependencies.config.php @@ -0,0 +1,44 @@ + [ + 'factories' => [ + IpApiLocationResolver::class => ConfigAbstractFactory::class, + GeoLite2LocationResolver::class => ConfigAbstractFactory::class, + EmptyIpLocationResolver::class => InvokableFactory::class, + ChainIpLocationResolver::class => ConfigAbstractFactory::class, + GeoLite2\GeoLite2Options::class => ConfigAbstractFactory::class, + GeoLite2\DbUpdater::class => ConfigAbstractFactory::class, + ], + 'aliases' => [ + IpLocationResolverInterface::class => ChainIpLocationResolver::class, + ], + ], + + ConfigAbstractFactory::class => [ + IpApiLocationResolver::class => ['httpClient'], + GeoLite2LocationResolver::class => [Reader::class], + ChainIpLocationResolver::class => [ + GeoLite2LocationResolver::class, + IpApiLocationResolver::class, + EmptyIpLocationResolver::class, + ], + GeoLite2\GeoLite2Options::class => ['config.geolite2'], + GeoLite2\DbUpdater::class => [ + GuzzleClient::class, + Filesystem::class, + GeoLite2\GeoLite2Options::class, + ], + ], + +]; diff --git a/module/Common/src/IpGeolocation/ChainIpLocationResolver.php b/module/IpGeolocation/src/ChainIpLocationResolver.php similarity index 95% rename from module/Common/src/IpGeolocation/ChainIpLocationResolver.php rename to module/IpGeolocation/src/ChainIpLocationResolver.php index 6d8659fa..2d837a7f 100644 --- a/module/Common/src/IpGeolocation/ChainIpLocationResolver.php +++ b/module/IpGeolocation/src/ChainIpLocationResolver.php @@ -1,7 +1,7 @@ httpClient = $this->prophesize(ClientInterface::class); $this->filesystem = $this->prophesize(Filesystem::class); $this->options = new GeoLite2Options([ - 'temp_dir' => __DIR__ . '/../../../test-resources', + 'temp_dir' => __DIR__ . '/../../test-resources', 'db_location' => 'db_location', 'download_from' => '', ]); diff --git a/module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php b/module/IpGeolocation/test/GeoLite2LocationResolverTest.php similarity index 91% rename from module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php rename to module/IpGeolocation/test/GeoLite2LocationResolverTest.php index 0f58515b..b1dc5866 100644 --- a/module/Common/test/IpGeolocation/GeoLite2LocationResolverTest.php +++ b/module/IpGeolocation/test/GeoLite2LocationResolverTest.php @@ -1,7 +1,7 @@ ./module/EventDispatcher/test + + ./module/IpGeolocation/test +