From 47ea4218d0bf0a9fae0052dce3e4923ed0657f1a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 19:38:46 +0200 Subject: [PATCH 1/4] Created PreviewGenerator module --- composer.json | 4 ++- module/CLI/config/dependencies.config.php | 2 +- .../ShortUrl/GeneratePreviewCommand.php | 2 +- .../ShortUrl/GeneratePreviewCommandTest.php | 2 +- module/Common/config/dependencies.config.php | 10 ------- module/Core/config/dependencies.config.php | 2 +- module/Core/src/Action/PreviewAction.php | 2 +- module/Core/test/Action/PreviewActionTest.php | 2 +- .../config/dependencies.config.php | 26 +++++++++++++++++++ .../PreviewGenerator/src/ConfigProvider.php | 15 +++++++++++ .../src/Image/ImageBuilder.php | 2 +- .../src/Image/ImageBuilderFactory.php | 2 +- .../src/Image/ImageBuilderInterface.php | 2 +- .../src/Image/ImageFactory.php | 2 +- .../src/Service/PreviewGenerator.php | 4 +-- .../src/Service/PreviewGeneratorInterface.php | 2 +- .../test/ConfigProviderTest.php | 26 +++++++++++++++++++ .../test/Image/ImageBuilderFactoryTest.php | 6 ++--- .../test/Image/ImageFactoryTest.php | 4 +-- .../test/Service/PreviewGeneratorTest.php | 6 ++--- phpunit.xml.dist | 4 +++ 21 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 module/PreviewGenerator/config/dependencies.config.php create mode 100644 module/PreviewGenerator/src/ConfigProvider.php rename module/{Common => PreviewGenerator}/src/Image/ImageBuilder.php (83%) rename module/{Common => PreviewGenerator}/src/Image/ImageBuilderFactory.php (95%) rename module/{Common => PreviewGenerator}/src/Image/ImageBuilderInterface.php (77%) rename module/{Common => PreviewGenerator}/src/Image/ImageFactory.php (95%) rename module/{Common => PreviewGenerator}/src/Service/PreviewGenerator.php (93%) rename module/{Common => PreviewGenerator}/src/Service/PreviewGeneratorInterface.php (87%) create mode 100644 module/PreviewGenerator/test/ConfigProviderTest.php rename module/{Common => PreviewGenerator}/test/Image/ImageBuilderFactoryTest.php (74%) rename module/{Common => PreviewGenerator}/test/Image/ImageFactoryTest.php (92%) rename module/{Common => PreviewGenerator}/test/Service/PreviewGeneratorTest.php (94%) diff --git a/composer.json b/composer.json index 65edeae5..2f7b201b 100644 --- a/composer.json +++ b/composer.json @@ -75,7 +75,8 @@ "Shlinkio\\Shlink\\Core\\": "module/Core/src", "Shlinkio\\Shlink\\Common\\": "module/Common/src", "Shlinkio\\Shlink\\EventDispatcher\\": "module/EventDispatcher/src", - "Shlinkio\\Shlink\\IpGeolocation\\": "module/IpGeolocation/src/" + "Shlinkio\\Shlink\\IpGeolocation\\": "module/IpGeolocation/src/", + "Shlinkio\\Shlink\\PreviewGenerator\\": "module/PreviewGenerator/src/" }, "files": [ "module/Common/functions/functions.php", @@ -94,6 +95,7 @@ "ShlinkioTest\\Shlink\\Common\\": "module/Common/test", "ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test", "ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test", + "ShlinkioTest\\Shlink\\PreviewGenerator\\": "module/PreviewGenerator/test", "Shlinkio\\Shlink\\TestUtils\\": "module/TestUtils/src" } }, diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index f014bcb2..2376e5af 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\Service\PreviewGenerator; use Shlinkio\Shlink\Core\Service; use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; +use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; 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/ShortUrl/GeneratePreviewCommand.php b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php index 9cabe664..3f33f7b0 100644 --- a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php +++ b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php @@ -5,8 +5,8 @@ namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; -use Shlinkio\Shlink\Common\Service\PreviewGeneratorInterface; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; +use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGeneratorInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php index 478977d5..80e7222f 100644 --- a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php @@ -8,9 +8,9 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\GeneratePreviewCommand; use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; -use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Service\ShortUrlService; +use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Zend\Paginator\Adapter\ArrayAdapter; diff --git a/module/Common/config/dependencies.config.php b/module/Common/config/dependencies.config.php index fec932e1..d4d3110d 100644 --- a/module/Common/config/dependencies.config.php +++ b/module/Common/config/dependencies.config.php @@ -25,10 +25,6 @@ return [ Middleware\LocaleMiddleware::class => ConfigAbstractFactory::class, Middleware\CloseDbConnectionMiddleware::class => ConfigAbstractFactory::class, IpAddress::class => Middleware\IpAddressMiddlewareFactory::class, - - Image\ImageBuilder::class => Image\ImageBuilderFactory::class, - - Service\PreviewGenerator::class => ConfigAbstractFactory::class, ], 'aliases' => [ 'httpClient' => GuzzleClient::class, @@ -47,12 +43,6 @@ return [ Template\Extension\TranslatorExtension::class => ['translator'], Middleware\LocaleMiddleware::class => ['translator'], Middleware\CloseDbConnectionMiddleware::class => ['em'], - - Service\PreviewGenerator::class => [ - Image\ImageBuilder::class, - Filesystem::class, - 'config.preview_generation.files_location', - ], ], ]; diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index 28ea8a56..283205c3 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -5,8 +5,8 @@ namespace Shlinkio\Shlink\Core; use Doctrine\Common\Cache\Cache; use Psr\EventDispatcher\EventDispatcherInterface; -use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Shlinkio\Shlink\Core\Response\NotFoundHandler; +use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; use Zend\Expressive\Router\RouterInterface; use Zend\Expressive\Template\TemplateRendererInterface; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; diff --git a/module/Core/src/Action/PreviewAction.php b/module/Core/src/Action/PreviewAction.php index a86a3358..5ada47ec 100644 --- a/module/Core/src/Action/PreviewAction.php +++ b/module/Core/src/Action/PreviewAction.php @@ -11,11 +11,11 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; use Shlinkio\Shlink\Common\Response\ResponseUtilsTrait; -use Shlinkio\Shlink\Common\Service\PreviewGeneratorInterface; use Shlinkio\Shlink\Core\Action\Util\ErrorResponseBuilderTrait; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; +use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGeneratorInterface; /** @deprecated */ class PreviewAction implements MiddlewareInterface diff --git a/module/Core/test/Action/PreviewActionTest.php b/module/Core/test/Action/PreviewActionTest.php index 3fba9948..f8f74d88 100644 --- a/module/Core/test/Action/PreviewActionTest.php +++ b/module/Core/test/Action/PreviewActionTest.php @@ -8,12 +8,12 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Server\RequestHandlerInterface; -use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Shlinkio\Shlink\Core\Action\PreviewAction; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\UrlShortener; +use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; use ShlinkioTest\Shlink\Common\Util\TestUtils; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; diff --git a/module/PreviewGenerator/config/dependencies.config.php b/module/PreviewGenerator/config/dependencies.config.php new file mode 100644 index 00000000..03b92fc0 --- /dev/null +++ b/module/PreviewGenerator/config/dependencies.config.php @@ -0,0 +1,26 @@ + [ + 'factories' => [ + Image\ImageBuilder::class => Image\ImageBuilderFactory::class, + Service\PreviewGenerator::class => ConfigAbstractFactory::class, + ], + ], + + ConfigAbstractFactory::class => [ + Service\PreviewGenerator::class => [ + Image\ImageBuilder::class, + Filesystem::class, + 'config.preview_generation.files_location', + ], + ], + +]; diff --git a/module/PreviewGenerator/src/ConfigProvider.php b/module/PreviewGenerator/src/ConfigProvider.php new file mode 100644 index 00000000..2a51f6c3 --- /dev/null +++ b/module/PreviewGenerator/src/ConfigProvider.php @@ -0,0 +1,15 @@ +configProvider = new ConfigProvider(); + } + + /** @test */ + public function configIsReturned(): void + { + $config = ($this->configProvider)(); + + $this->assertArrayHasKey('dependencies', $config); + } +} diff --git a/module/Common/test/Image/ImageBuilderFactoryTest.php b/module/PreviewGenerator/test/Image/ImageBuilderFactoryTest.php similarity index 74% rename from module/Common/test/Image/ImageBuilderFactoryTest.php rename to module/PreviewGenerator/test/Image/ImageBuilderFactoryTest.php index 8a5aaab1..935e4526 100644 --- a/module/Common/test/Image/ImageBuilderFactoryTest.php +++ b/module/PreviewGenerator/test/Image/ImageBuilderFactoryTest.php @@ -1,11 +1,11 @@ ./module/IpGeolocation/test + + ./module/PreviewGenerator/test + @@ -32,6 +35,7 @@ ./module/Core/src/Repository + ./module/TestUtils From 27a6f355345cc77b8604e9286ed12eaf0507d02a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 19:40:30 +0200 Subject: [PATCH 2/4] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e1cf5b2..5d49e7cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this #### Changed * [#450](https://github.com/shlinkio/shlink/issues/450) Added PHP 7.4 to the build matrix, as an allowed-to-fail env. +* [#443](https://github.com/shlinkio/shlink/issues/443) Split some logic into independent modules. #### Deprecated From ef70e44a17917b9c29122fb19cb35dcca74259fb Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 19:43:06 +0200 Subject: [PATCH 3/4] Registered Preview generator module --- config/config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config.php b/config/config.php index d5776eef..8cc7c38a 100644 --- a/config/config.php +++ b/config/config.php @@ -22,6 +22,7 @@ return (new ConfigAggregator\ConfigAggregator([ CLI\ConfigProvider::class, Rest\ConfigProvider::class, EventDispatcher\ConfigProvider::class, + PreviewGenerator\ConfigProvider::class, new ConfigAggregator\PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), env('APP_ENV') === 'test' ? new ConfigAggregator\PhpFileProvider('config/test/*.global.php') From 095f075ca95fabd20c145796e5392678a5c4f3a3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 19:47:15 +0200 Subject: [PATCH 4/4] Moved PreviewGenerationException to PreviewGenerator module --- module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php | 2 +- module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php | 2 +- module/Core/src/Action/PreviewAction.php | 2 +- .../src/Exception/PreviewGenerationException.php | 2 +- module/PreviewGenerator/src/Service/PreviewGenerator.php | 2 +- .../PreviewGenerator/src/Service/PreviewGeneratorInterface.php | 2 +- module/PreviewGenerator/test/Service/PreviewGeneratorTest.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename module/{Common => PreviewGenerator}/src/Exception/PreviewGenerationException.php (85%) diff --git a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php index 3f33f7b0..22c4a998 100644 --- a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php +++ b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Util\ExitCodes; -use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; +use Shlinkio\Shlink\PreviewGenerator\Exception\PreviewGenerationException; use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGeneratorInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; diff --git a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php index 80e7222f..f4ea4c92 100644 --- a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\GeneratePreviewCommand; -use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Service\ShortUrlService; +use Shlinkio\Shlink\PreviewGenerator\Exception\PreviewGenerationException; use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; diff --git a/module/Core/src/Action/PreviewAction.php b/module/Core/src/Action/PreviewAction.php index 5ada47ec..276c7ba5 100644 --- a/module/Core/src/Action/PreviewAction.php +++ b/module/Core/src/Action/PreviewAction.php @@ -9,12 +9,12 @@ use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Shlinkio\Shlink\Common\Exception\PreviewGenerationException; use Shlinkio\Shlink\Common\Response\ResponseUtilsTrait; use Shlinkio\Shlink\Core\Action\Util\ErrorResponseBuilderTrait; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; +use Shlinkio\Shlink\PreviewGenerator\Exception\PreviewGenerationException; use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGeneratorInterface; /** @deprecated */ diff --git a/module/Common/src/Exception/PreviewGenerationException.php b/module/PreviewGenerator/src/Exception/PreviewGenerationException.php similarity index 85% rename from module/Common/src/Exception/PreviewGenerationException.php rename to module/PreviewGenerator/src/Exception/PreviewGenerationException.php index a889474a..c02ea7ed 100644 --- a/module/Common/src/Exception/PreviewGenerationException.php +++ b/module/PreviewGenerator/src/Exception/PreviewGenerationException.php @@ -1,7 +1,7 @@