From 47ea4218d0bf0a9fae0052dce3e4923ed0657f1a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 19:38:46 +0200 Subject: [PATCH] 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