From a1abe9845156a7da06df69b747f6db5dbf57d3f3 Mon Sep 17 00:00:00 2001 From: Rick van Laarhoven Date: Fri, 5 Aug 2016 17:16:21 +0200 Subject: [PATCH 01/20] Removed deprecated factory_class and factory_method --- Resources/doc/cache-resolver/aws_s3.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Resources/doc/cache-resolver/aws_s3.rst b/Resources/doc/cache-resolver/aws_s3.rst index 5ac8115b8..d6523c83f 100644 --- a/Resources/doc/cache-resolver/aws_s3.rst +++ b/Resources/doc/cache-resolver/aws_s3.rst @@ -64,8 +64,7 @@ You have to set up the services required: services: acme.amazon_s3: class: Aws\S3\S3Client - factory_class: Aws\S3\S3Client - factory_method: factory + factory: [Aws\S3\S3Client, factory] arguments: - key: %amazon.s3.key% @@ -87,8 +86,7 @@ must be an associative array containing key and secret. acme.amazon_s3: class: Aws\S3\S3Client - factory_class: Aws\S3\S3Client - factory_method: factory + factory: [Aws\S3\S3Client, factory] arguments: - credentials: { key: %amazon.s3.key%, secret: %amazon.s3.secret% } From 210922c6405df9e65cad7ecbed983c26740223fd Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Sun, 30 Oct 2016 19:32:11 -0400 Subject: [PATCH 02/20] correct example filter yml definitions in docs (fixes #818) and other minor tweaks --- Resources/doc/filters/sizing.rst | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Resources/doc/filters/sizing.rst b/Resources/doc/filters/sizing.rst index f1332e74b..7ac594b6c 100644 --- a/Resources/doc/filters/sizing.rst +++ b/Resources/doc/filters/sizing.rst @@ -31,10 +31,10 @@ Example configuration: thumbnail: # set the thumbnail size to "32x32" pixels - - size: [32, 32] + size: [32, 32] # crop the input image, if required - - mode: outbound + mode: outbound .. seealso:: @@ -84,10 +84,10 @@ Example configuration: crop: # set the size of the cropping area - - size: [ 300, 600 ] + size: [ 300, 600 ] # set the starting coordinates of the crop - - start: [ 040, 160 ] + start: [ 040, 160 ] Crop Options @@ -127,34 +127,37 @@ Example configuration: relative_resize: # given 50x40px, output 75x60px using "heighten" option - - heighten: 60 + heighten: 60 # name our second filter set "my_widen_filter" my_widen_filter: + filters: # use and setup the "relative_resize" filter relative_resize: # given 50x40px, output 32x26px using "widen" option - - widen: 32 + widen: 32 # name our second filter set "my_increase_filter" my_increase_filter: + filters: # use and setup the "relative_resize" filter relative_resize: # given 50x40px, output 60x50px, using "increase" option - - increase: 10 + increase: 10 # name our second filter set "my_scale_filter" my_scale_filter: + filters: # use and setup the "relative_resize" filter relative_resize: # given 50x40px, output 125x100px using "scale" option - - scale: 2.5 + scale: 2.5 .. tip:: @@ -206,40 +209,40 @@ Example configuration: filters: # use and setup the "scale" filter - scale: + resize: # given 1920x1600px -> output 960x800px (relative down-scale) - - to: 0.5 + to: 0.5 # name our first filter set "my_ratio_up_scale_filter" my_ratio_up_scale_filter: filters: # use and setup the "scale" filter - scale: + resize: # given 1920x1600px -> output 5760x3200px (relative up-scale) - - to: 2 + to: 2 # name our third filter set "my_dim_down_scale_filter" my_dim_down_scale_filter: filters: # use and setup the "scale" filter - scale: + resize: # input 1200x1600px -> output 750x1000px (relative down-scale) - - dim: [ 800, 1000 ] + dim: [ 800, 1000 ] # name our fourth filter set "my_dim_up_scale_filter" my_dim_up_scale_filter: filters: # use and setup the "scale" filter - scale: + resize: # input 300x900px -> output 900x2700px (relative up-scale) - - dim: [ 1200, 2700 ] + dim: [ 1200, 2700 ] Scale Options @@ -358,4 +361,3 @@ Up Scale Options .. _`BoxInterface`: http://imagine.readthedocs.io/en/latest/usage/coordinates.html#boxinterface .. _`Imagine Library`: http://imagine.readthedocs.io/en/latest/ - From c8648cab0fa7cba276f4ff7758c72fa62a8f20be Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Sun, 30 Oct 2016 19:51:54 -0400 Subject: [PATCH 03/20] correct accidental regression introduced in prior commit --- Resources/doc/filters/sizing.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Resources/doc/filters/sizing.rst b/Resources/doc/filters/sizing.rst index 7ac594b6c..04061a560 100644 --- a/Resources/doc/filters/sizing.rst +++ b/Resources/doc/filters/sizing.rst @@ -209,7 +209,7 @@ Example configuration: filters: # use and setup the "scale" filter - resize: + scale: # given 1920x1600px -> output 960x800px (relative down-scale) to: 0.5 @@ -219,7 +219,7 @@ Example configuration: filters: # use and setup the "scale" filter - resize: + scale: # given 1920x1600px -> output 5760x3200px (relative up-scale) to: 2 @@ -229,7 +229,7 @@ Example configuration: filters: # use and setup the "scale" filter - resize: + scale: # input 1200x1600px -> output 750x1000px (relative down-scale) dim: [ 800, 1000 ] @@ -239,7 +239,7 @@ Example configuration: filters: # use and setup the "scale" filter - resize: + scale: # input 300x900px -> output 900x2700px (relative up-scale) dim: [ 1200, 2700 ] From dba4474a6ba29c1ca7adb4a2e34055802e214927 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Wed, 23 Nov 2016 18:24:44 -0500 Subject: [PATCH 04/20] added coveralls reporting to travis --- .coveralls.yml | 4 ++++ .gitignore | 11 ++++++----- .travis.yml | 10 ++++++++-- composer.json | 1 + phpunit.xml.dist | 25 +++++++++++++++++++++++-- 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 000000000..68e2b531d --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,4 @@ +--- + +coverage_clover : var/build/clover.xml +json_path : var/build/coveralls-upload.json diff --git a/.gitignore b/.gitignore index 2f8f9d007..3cf9f44af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /bin/ /phpunit.xml -composer.lock -composer.phar -vendor/ -Tests/Functional/app/web/media/cache -.idea/ +/composer.lock +/composer.phar +/vendor/ +/Tests/Functional/app/web/media/cache +/.idea/ +/var/ diff --git a/.travis.yml b/.travis.yml index e3b56a12d..cffb5d136 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,14 +40,20 @@ matrix: before_install: - composer self-update + - if [ "${TRAVIS_PHP_VERSION}" == "5.3" ]; then composer remove --no-update --dev satooshi/php-coveralls; fi; - if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ]; then echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi; - if [ "${SYMFONY_VERSION:0:3}" == "2.3" ]; then composer remove --dev friendsofphp/php-cs-fixer --no-update; fi; - if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION}" != "5.3" ]; then composer require --dev league/flysystem:~1.0 --no-update; fi; - if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:1}" != "7" ]; then composer require --dev doctrine/mongodb-odm:~1.0 --no-update; yes "" | pecl -q install -f mongo; fi; - if [ "${SYMFONY_VERSION:-x}" != "x" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; -install: composer update --prefer-source $COMPOSER_FLAGS +install: + - composer update --prefer-source $COMPOSER_FLAGS -script: ./bin/phpunit --coverage-text +script: + - ./bin/phpunit -vvv + +after_script: + - if [ "${TRAVIS_PHP_VERSION}" != "5.3" ]; then bin/coveralls -vvv; fi; ... diff --git a/composer.json b/composer.json index 3e1aedb68..5a9a88400 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "friendsofphp/php-cs-fixer": "~2.0", "phpunit/phpunit": "~4.3", "psr/log": "~1.0", + "satooshi/php-coveralls": "~1.0", "sllh/php-cs-fixer-styleci-bridge": "~2.1", "symfony/browser-kit": "~2.3|~3.0", "symfony/console": "~2.3|~3.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 85d1871a4..1b3d7cb02 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,18 @@ - + - + ./Tests @@ -18,4 +27,16 @@ + + + + + + + + + + + + From d8435eb4867a7fb5dc970d3ce11e58f88d383442 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Wed, 23 Nov 2016 23:25:31 -0500 Subject: [PATCH 05/20] added coveralls reporting to travis removed html coverage generation updated readme info urls --- README.md | 6 +++--- phpunit.xml.dist | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7adf4dc15..152763a70 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LiipImagineBundle -| Travis-CI | Style-CI | Downloads | Release | -|:----------------------:|:-----------------------:|:-----------------------:|:-----------------------:| -| [![Travis](https://src.run/shield/liip/LiipImagineBundle/travis.svg)](http://travis-ci.org/liip/LiipImagineBundle) | [![Style CI](https://src.run/shield/liip/LiipImagineBundle:2515323/styleci.svg)](https://styleci.io/repos/2515323) |[![Downloads](https://src.run/shield/liip/LiipImagineBundle/packagist_dt.svg)](https://packagist.org/packages/liip/imagine-bundle) | [![Latest Stable Version](https://src.run/shield/liip/LiipImagineBundle/packagist_v.svg)](https://packagist.org/packages/liip/imagine-bundle) | +| Travis-CI | Style-CI | Coverage | Downloads | Release | +|:----------------------:|:-----------------------:|:-----------------------:|:-----------------------:|:-----------------------:| +| [![Travis](https://src.run/shield/liip/LiipImagineBundle/master/travis.svg)](https://src.run/service/liip/LiipImagineBundle/master/travis) | [![Style CI](https://src.run/shield/liip/LiipImagineBundle/master/styleci.svg)](https://src.run/service/liip/LiipImagineBundle/master/styleci) | [![Coverage](https://src.run/shield/liip/LiipImagineBundle/master/coveralls.svg)](https://src.run/service/liip/LiipImagineBundle/master/coveralls) | [![Downloads](https://src.run/shield/liip/LiipImagineBundle/packagist_dt.svg)](https://src.run/service/liip/LiipImagineBundle/packagist) | [![Latest Stable Version](https://src.run/shield/liip/LiipImagineBundle/packagist_v.svg)](https://src.run/service/liip/LiipImagineBundle/packagist) | *This bundle provides an image manipulation abstraction toolkit for [Symfony](http://symfony.com/)-based projects.* diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1b3d7cb02..2188432e8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,7 +29,6 @@ - From c708b793f6479168ffac338bfd64916c1b63897c Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Wed, 23 Nov 2016 23:47:19 -0500 Subject: [PATCH 06/20] updated readme for branch --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 152763a70..7b75dfb1d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ | Travis-CI | Style-CI | Coverage | Downloads | Release | |:----------------------:|:-----------------------:|:-----------------------:|:-----------------------:|:-----------------------:| -| [![Travis](https://src.run/shield/liip/LiipImagineBundle/master/travis.svg)](https://src.run/service/liip/LiipImagineBundle/master/travis) | [![Style CI](https://src.run/shield/liip/LiipImagineBundle/master/styleci.svg)](https://src.run/service/liip/LiipImagineBundle/master/styleci) | [![Coverage](https://src.run/shield/liip/LiipImagineBundle/master/coveralls.svg)](https://src.run/service/liip/LiipImagineBundle/master/coveralls) | [![Downloads](https://src.run/shield/liip/LiipImagineBundle/packagist_dt.svg)](https://src.run/service/liip/LiipImagineBundle/packagist) | [![Latest Stable Version](https://src.run/shield/liip/LiipImagineBundle/packagist_v.svg)](https://src.run/service/liip/LiipImagineBundle/packagist) | +| [![Travis](https://src.run/shield/liip/LiipImagineBundle/2.0/travis.svg)](https://src.run/service/liip/LiipImagineBundle/2.0/travis) | [![Style CI](https://src.run/shield/liip/LiipImagineBundle/2.0/styleci.svg)](https://src.run/service/liip/LiipImagineBundle/2.0/styleci) | [![Coverage](https://src.run/shield/liip/LiipImagineBundle/2.0/coveralls.svg)](https://src.run/service/liip/LiipImagineBundle/2.0/coveralls) | [![Downloads](https://src.run/shield/liip/LiipImagineBundle/packagist_dt.svg)](https://src.run/service/liip/LiipImagineBundle/packagist) | [![Latest Stable Version](https://src.run/shield/liip/LiipImagineBundle/packagist_v.svg)](https://src.run/service/liip/LiipImagineBundle/packagist) | *This bundle provides an image manipulation abstraction toolkit for [Symfony](http://symfony.com/)-based projects.* - + ## Overview - [Filter Sets](http://symfony.com/doc/master/bundles/LiipImagineBundle/basic-usage.html): From 32c0a1fa268be0f496e736ea8f9e18c9db569194 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 13:28:40 +0200 Subject: [PATCH 07/20] Split image filtering functionality from ImagineController to new FilterService --- Controller/ImagineController.php | 171 +++++++----------- Imagine/Data/DataManager.php | 2 +- Resources/config/imagine.xml | 11 +- Service/FilterService.php | 164 +++++++++++++++++ Tests/AbstractTest.php | 9 + Tests/Controller/ImagineControllerTest.php | 6 +- .../LiipImagineExtensionTest.php | 4 +- .../Controller/ImagineControllerTest.php | 2 +- 8 files changed, 247 insertions(+), 122 deletions(-) create mode 100644 Service/FilterService.php diff --git a/Controller/ImagineController.php b/Controller/ImagineController.php index 6fc81fe06..9519e68d2 100644 --- a/Controller/ImagineController.php +++ b/Controller/ImagineController.php @@ -14,11 +14,9 @@ use Imagine\Exception\RuntimeException; use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException; use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException; -use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Cache\SignerInterface; use Liip\ImagineBundle\Imagine\Data\DataManager; -use Liip\ImagineBundle\Imagine\Filter\FilterManager; -use Psr\Log\LoggerInterface; +use Liip\ImagineBundle\Service\FilterService; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -27,165 +25,118 @@ class ImagineController { /** - * @var DataManager - */ - protected $dataManager; - - /** - * @var FilterManager + * @var FilterService */ - protected $filterManager; + private $filterService; /** - * @var CacheManager + * @var DataManager */ - protected $cacheManager; + private $dataManager; /** * @var SignerInterface */ - protected $signer; - - /** - * @var LoggerInterface - */ - protected $logger; + private $signer; /** - * @param DataManager $dataManager - * @param FilterManager $filterManager - * @param CacheManager $cacheManager + * @param FilterService $filterService + * @param DataManager $dataManager * @param SignerInterface $signer */ - public function __construct( - DataManager $dataManager, - FilterManager $filterManager, - CacheManager $cacheManager, - SignerInterface $signer, - LoggerInterface $logger = null - ) { + public function __construct(FilterService $filterService, DataManager $dataManager, SignerInterface $signer) + { + $this->filterService = $filterService; $this->dataManager = $dataManager; - $this->filterManager = $filterManager; - $this->cacheManager = $cacheManager; $this->signer = $signer; - $this->logger = $logger; } /** - * This action applies a given filter to a given image, optionally saves the image and outputs it to the browser at the same time. + * This action applies a given filter to a given image, saves the image and redirects the browser to the stored + * image. + * + * The resulting image is cached so subsequent requests will redirect to the cached image instead applying the + * filter and storing the image again. * - * @param Request $request - * @param string $path - * @param string $filter + * @param \Symfony\Component\HttpFoundation\Request $request + * @param string $path + * @param string $filter * * @throws \RuntimeException - * @throws BadRequestHttpException + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function filterAction(Request $request, $path, $filter) { - // decoding special characters and whitespaces from path obtained from url $path = urldecode($path); $resolver = $request->get('resolver'); try { - if (!$this->cacheManager->isStored($path, $filter, $resolver)) { - try { - $binary = $this->dataManager->find($filter, $path); - } catch (NotLoadableException $e) { - if ($defaultImageUrl = $this->dataManager->getDefaultImageUrl($filter)) { - return new RedirectResponse($defaultImageUrl); - } - - throw new NotFoundHttpException('Source image could not be found', $e); - } - - $this->cacheManager->store( - $this->filterManager->applyFilter($binary, $filter), - $path, - $filter, - $resolver - ); - } + $this->filterService->createFilteredImage($path, $filter, $resolver); - return new RedirectResponse($this->cacheManager->resolve($path, $filter, $resolver), 301); - } catch (NonExistingFilterException $e) { - $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $path, $e->getMessage()); - - if (null !== $this->logger) { - $this->logger->debug($message); + return new RedirectResponse($this->filterService->getUrlOfFilteredImage($path, $filter, $resolver), 301); + } catch (NotLoadableException $e) { + if ($this->dataManager->getDefaultImageUrl($filter) !== null) { + return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter)); } - throw new NotFoundHttpException($message, $e); + throw new NotFoundHttpException(sprintf('Source image for path "%s" could not be found', $path)); + } catch (NonExistingFilterException $e) { + throw new NotFoundHttpException(sprintf('Requested non-existing filter "%s"', $filter)); } catch (RuntimeException $e) { throw new \RuntimeException(sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $path, $filter, $e->getMessage()), 0, $e); } } /** - * This action applies a given filter to a given image, optionally saves the image and outputs it to the browser at the same time. + * This action applies a given filter -merged with additional runtime filters- to a given image, saves the image and + * redirects the browser to the stored image. + * + * The resulting image is cached so subsequent requests will redirect to the cached image instead applying the + * filter and storing the image again. * - * @param Request $request - * @param string $hash - * @param string $path - * @param string $filter + * @param \Symfony\Component\HttpFoundation\Request $request + * @param string $hash + * @param string $path + * @param string $filter * * @throws \RuntimeException - * @throws BadRequestHttpException + * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function filterRuntimeAction(Request $request, $hash, $path, $filter) { $resolver = $request->get('resolver'); + $runtimeConfig = $request->query->get('filters', []); - try { - $filters = $request->query->get('filters', array()); - - if (!is_array($filters)) { - throw new NotFoundHttpException(sprintf('Filters must be an array. Value was "%s"', $filters)); - } - - if (true !== $this->signer->check($hash, $path, $filters)) { - throw new BadRequestHttpException(sprintf( - 'Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', - $path, - $filter, - json_encode($filters) - )); - } - - try { - $binary = $this->dataManager->find($filter, $path); - } catch (NotLoadableException $e) { - if ($defaultImageUrl = $this->dataManager->getDefaultImageUrl($filter)) { - return new RedirectResponse($defaultImageUrl); - } - - throw new NotFoundHttpException(sprintf('Source image could not be found for path "%s" and filter "%s"', $path, $filter), $e); - } - - $rcPath = $this->cacheManager->getRuntimePath($path, $filters); + if (!is_array($runtimeConfig)) { + throw new NotFoundHttpException(sprintf('Filters must be an array. Value was "%s"', $runtimeConfig)); + } - $this->cacheManager->store( - $this->filterManager->applyFilter($binary, $filter, array( - 'filters' => $filters, - )), - $rcPath, + if (true !== $this->signer->check($hash, $path, $runtimeConfig)) { + throw new BadRequestHttpException(sprintf( + 'Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', + $path, $filter, - $resolver - ); + json_encode($runtimeConfig) + )); + } - return new RedirectResponse($this->cacheManager->resolve($rcPath, $filter, $resolver), 301); - } catch (NonExistingFilterException $e) { - $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $hash.'/'.$path, $e->getMessage()); + try { + $this->filterService->createFilteredImageWithRuntimeFilters($path, $filter, $runtimeConfig, $resolver); - if (null !== $this->logger) { - $this->logger->debug($message); + return new RedirectResponse($this->filterService->getUrlOfFilteredImageWithRuntimeFilters($path, $filter, $runtimeConfig, $resolver), 301); + } catch (NotLoadableException $e) { + if ($this->dataManager->getDefaultImageUrl($filter) !== null) { + return new RedirectResponse($this->dataManager->getDefaultImageUrl($filter)); } - throw new NotFoundHttpException($message, $e); + throw new NotFoundHttpException(sprintf('Source image for path "%s" could not be found', $path)); + } catch (NonExistingFilterException $e) { + throw new NotFoundHttpException(sprintf('Requested non-existing filter "%s"', $filter)); } catch (RuntimeException $e) { throw new \RuntimeException(sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $hash.'/'.$path, $filter, $e->getMessage()), 0, $e); } diff --git a/Imagine/Data/DataManager.php b/Imagine/Data/DataManager.php index de5cddf1d..5b74bcf7a 100644 --- a/Imagine/Data/DataManager.php +++ b/Imagine/Data/DataManager.php @@ -149,7 +149,7 @@ public function find($filter, $path) * * @param string $filter * - * @return string + * @return string|null */ public function getDefaultImageUrl($filter) { diff --git a/Resources/config/imagine.xml b/Resources/config/imagine.xml index 771cd7438..2680c1ec4 100644 --- a/Resources/config/imagine.xml +++ b/Resources/config/imagine.xml @@ -60,14 +60,19 @@ %liip_imagine.filter_sets% + + + + + + + + - - - diff --git a/Service/FilterService.php b/Service/FilterService.php new file mode 100644 index 000000000..b9d18dfef --- /dev/null +++ b/Service/FilterService.php @@ -0,0 +1,164 @@ +dataManager = $dataManager; + $this->filterManager = $filterManager; + $this->cacheManager = $cacheManager; + $this->logger = $logger ? $logger : new NullLogger(); + } + + /** + * @param string $path + * @param string $filter + * @param string $resolver + * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException + * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + */ + public function createFilteredImage($path, $filter, $resolver = null) + { + if ($this->cacheManager->isStored($path, $filter, $resolver)) { + return; + } + + $filteredBinary = $this->createFilteredBinary( + $path, + $filter + ); + + $this->cacheManager->store( + $filteredBinary, + $path, + $filter, + $resolver + ); + } + + /** + * @param string $path + * @param string $filter + * @param string $resolver + * @param array $runtimeFilters + * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException + * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + */ + public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) + { + $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); + if ($this->cacheManager->isStored($runtimePath, $filter, $resolver)) { + return; + } + + $filteredBinary = $this->createFilteredBinary( + $path, + $filter, + $runtimeFilters + ); + + $this->cacheManager->store( + $filteredBinary, + $runtimePath, + $filter, + $resolver + ); + } + + /** + * @param string $path + * @param string $filter + * @param string $resolver + * @return string + */ + public function getUrlOfFilteredImage($path, $filter, $resolver) + { + return $this->cacheManager->resolve($path, $filter, $resolver); + } + + /** + * @param string $path + * @param string $filter + * @param string $resolver + * @param array $runtimeFilters + * @return string + */ + public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) + { + $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); + return $this->cacheManager->resolve($runtimePath, $filter, $resolver); + } + + /** + * @param string $path + * @param string $filter + * @param array|null $runtimeFilters + * @return \Liip\ImagineBundle\Binary\BinaryInterface + * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + */ + private function createFilteredBinary($path, $filter, array $runtimeFilters = []) + { + $binary = $this->dataManager->find($filter, $path); + + try { + return $this->filterManager->applyFilter($binary, $filter, [ + 'filters' => $runtimeFilters, + ]); + } catch (NonExistingFilterException $e) { + $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $path, $e->getMessage()); + + $this->logger->debug($message); + + throw $e; + } + } +} diff --git a/Tests/AbstractTest.php b/Tests/AbstractTest.php index 1e3c71aa0..2052b0ace 100644 --- a/Tests/AbstractTest.php +++ b/Tests/AbstractTest.php @@ -23,6 +23,7 @@ use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use Liip\ImagineBundle\Imagine\Filter\FilterManager; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface; +use Liip\ImagineBundle\Service\FilterService; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Filesystem\Filesystem; @@ -213,6 +214,14 @@ protected function createFilterManagerMock() return $this->createObjectMock('\Liip\ImagineBundle\Imagine\Filter\FilterManager', array(), false); } + /** + * @return \PHPUnit_Framework_MockObject_MockObject|FilterService + */ + protected function createFilterServiceMock() + { + return $this->createObjectMock('\Liip\ImagineBundle\Service\FilterService'); + } + /** * @return \PHPUnit_Framework_MockObject_MockObject|DataManager */ diff --git a/Tests/Controller/ImagineControllerTest.php b/Tests/Controller/ImagineControllerTest.php index d93da8486..e637d57ee 100644 --- a/Tests/Controller/ImagineControllerTest.php +++ b/Tests/Controller/ImagineControllerTest.php @@ -22,11 +22,9 @@ class ImagineControllerTest extends AbstractTest public function testConstruction() { new ImagineController( + $this->createFilterServiceMock(), $this->createDataManagerMock(), - $this->createFilterManagerMock(), - $this->createCacheManagerMock(), - $this->createSignerInterfaceMock(), - $this->createLoggerInterfaceMock() + $this->createSignerInterfaceMock() ); } } diff --git a/Tests/DependencyInjection/LiipImagineExtensionTest.php b/Tests/DependencyInjection/LiipImagineExtensionTest.php index 5b8492ffc..bb5cc3cee 100644 --- a/Tests/DependencyInjection/LiipImagineExtensionTest.php +++ b/Tests/DependencyInjection/LiipImagineExtensionTest.php @@ -52,11 +52,9 @@ public function testLoadWithDefaults() $this->assertDICConstructorArguments( $this->containerBuilder->getDefinition('liip_imagine.controller'), array( + new Reference('liip_imagine.service.filter'), new Reference('liip_imagine.data.manager'), - new Reference('liip_imagine.filter.manager'), - new Reference('liip_imagine.cache.manager'), new Reference('liip_imagine.cache.signer'), - new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), ) ); } diff --git a/Tests/Functional/Controller/ImagineControllerTest.php b/Tests/Functional/Controller/ImagineControllerTest.php index 85d1d9c4e..047a3fe4d 100644 --- a/Tests/Functional/Controller/ImagineControllerTest.php +++ b/Tests/Functional/Controller/ImagineControllerTest.php @@ -89,7 +89,7 @@ public function testShouldThrowNotFoundHttpExceptionIfFiltersNotArray() /** * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - * @expectedExceptionMessage Source image could not be found + * @expectedExceptionMessage Source image for path "images/shrodinger_cats_which_not_exist.jpeg" could not be found */ public function testShouldThrowNotFoundHttpExceptionIfFileNotExists() { From 58603f326ccea75ed7577aad5d768746b411e274 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 13:41:12 +0200 Subject: [PATCH 08/20] README displays usage of new FilterService instead of ImagineController --- README.md | 75 +++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index f86fb0efc..b75f26e16 100644 --- a/README.md +++ b/README.md @@ -299,8 +299,8 @@ from our documentation. ## Use as a Service If you need to use your defined "filter sets" from within your controller, you -can fetch this bundle's controller from the service container and handle -the response yourself. +can fetch this bundle's FilterService from the service container to do the heavy +lifting for you. ```php container - ->get('liip_imagine.controller'); - - /** @var RedirectResponse */ - $imagemanagerResponse = $imagine - ->filterAction( - $this->request, // http request - 'uploads/foo.jpg', // original image you want to apply a filter to - 'my_thumb' // filter defined in config.yml - ); - - /** @var CacheManager */ - $cacheManager = $this - ->container - ->get('liip_imagine.cache.manager'); - - /** @var string */ - $sourcePath = $cacheManager - ->getBrowserPath( - 'uploads/foo.jpg', - 'my_thumb' - ); + ->get('liip_imagine.service.filter'); + + // 1) Simple filter, OR + $imagine->createFilteredImage('uploads/foo.jpg', 'my_thumb'); + $resourcePath = $imagine->getUrlOfFilteredImage('uploads/foo.jpg', 'my_thumb'); + + // 2) Runtime configuration + $runtimeConfig = [ + 'thumbnail' => [ + 'size' => [200, 200] + ], + ]; + $imagine->createFilteredImageWithRuntimeFilters( + 'uploads/foo.jpg', + 'my_thumb', + $runtimeConfig + ); + $resourcePath = $imagine->getUrlOfFilteredImageWithRuntimeFilters( + 'uploads/foo.jpg', + 'my_thumb', + $runtimeConfig + ); // .. } @@ -341,32 +342,6 @@ class MyController extends Controller ?> ``` -If you need to add more logic, the recommended solution is to either -extend `ImagineController.php` or use it as the basis for your own -implementation. - -To use the controller in another service, you have to simulate a new request. - -```php -container - ->get('liip_imagine.controller'); - -/** @var Response */ -$response = $imagine - ->filterAction( - new Symfony\Component\HttpFoundation\Request(), - 'uploads/foo.jpg', - 'my_thumb' - ); - -?> -``` - - ## Data Roots By default, Symfony's `web/` directory is registered as a data root to load From 6681c81a883430db57237c17cd55c13cdb9e8aba Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 13:48:23 +0200 Subject: [PATCH 09/20] Use new FilterService in ResolveCacheCommand --- Command/ResolveCacheCommand.php | 22 +++++++--------------- Service/FilterService.php | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Command/ResolveCacheCommand.php b/Command/ResolveCacheCommand.php index 8aa69a8ba..7050297fd 100644 --- a/Command/ResolveCacheCommand.php +++ b/Command/ResolveCacheCommand.php @@ -14,6 +14,7 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Data\DataManager; use Liip\ImagineBundle\Imagine\Filter\FilterManager; +use Liip\ImagineBundle\Service\FilterService; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -63,12 +64,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $paths = $input->getArgument('paths'); $filters = $input->getOption('filters'); - /* @var FilterManager filterManager */ + /* @var FilterManager $filterManager */ $filterManager = $this->getContainer()->get('liip_imagine.filter.manager'); - /* @var CacheManager cacheManager */ - $cacheManager = $this->getContainer()->get('liip_imagine.cache.manager'); - /* @var DataManager dataManager */ - $dataManager = $this->getContainer()->get('liip_imagine.data.manager'); + + /* @var FilterService $filterService */ + $filterService = $this->getContainer()->get('liip_imagine.service.filter'); if (empty($filters)) { $filters = array_keys($filterManager->getFilterConfiguration()->all()); @@ -76,17 +76,9 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($paths as $path) { foreach ($filters as $filter) { - if (!$cacheManager->isStored($path, $filter)) { - $binary = $dataManager->find($filter, $path); - - $cacheManager->store( - $filterManager->applyFilter($binary, $filter), - $path, - $filter - ); - } + $filterService->createFilteredImage($path, $filter); - $output->writeln($cacheManager->resolve($path, $filter)); + $output->writeln($filterService->getUrlOfFilteredImage($path, $filter)); } } } diff --git a/Service/FilterService.php b/Service/FilterService.php index b9d18dfef..81696c11c 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -120,7 +120,7 @@ public function createFilteredImageWithRuntimeFilters($path, $filter, array $run * @param string $resolver * @return string */ - public function getUrlOfFilteredImage($path, $filter, $resolver) + public function getUrlOfFilteredImage($path, $filter, $resolver = null) { return $this->cacheManager->resolve($path, $filter, $resolver); } From f7747043acd88ab61ce2165b97b076810da6823a Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 14:16:58 +0200 Subject: [PATCH 10/20] Use long array notation since PHP 5.3 is still supported in Travis --- Controller/ImagineController.php | 2 +- Service/FilterService.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Controller/ImagineController.php b/Controller/ImagineController.php index 9519e68d2..d476d9fda 100644 --- a/Controller/ImagineController.php +++ b/Controller/ImagineController.php @@ -110,7 +110,7 @@ public function filterAction(Request $request, $path, $filter) public function filterRuntimeAction(Request $request, $hash, $path, $filter) { $resolver = $request->get('resolver'); - $runtimeConfig = $request->query->get('filters', []); + $runtimeConfig = $request->query->get('filters', array()); if (!is_array($runtimeConfig)) { throw new NotFoundHttpException(sprintf('Filters must be an array. Value was "%s"', $runtimeConfig)); diff --git a/Service/FilterService.php b/Service/FilterService.php index 81696c11c..992e3de62 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -93,7 +93,7 @@ public function createFilteredImage($path, $filter, $resolver = null) * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException */ - public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) + public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = array(), $resolver = null) { $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); if ($this->cacheManager->isStored($runtimePath, $filter, $resolver)) { @@ -132,7 +132,7 @@ public function getUrlOfFilteredImage($path, $filter, $resolver = null) * @param array $runtimeFilters * @return string */ - public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) + public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = array(), $resolver = null) { $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); return $this->cacheManager->resolve($runtimePath, $filter, $resolver); @@ -145,14 +145,14 @@ public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $r * @return \Liip\ImagineBundle\Binary\BinaryInterface * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException */ - private function createFilteredBinary($path, $filter, array $runtimeFilters = []) + private function createFilteredBinary($path, $filter, array $runtimeFilters = array()) { $binary = $this->dataManager->find($filter, $path); try { - return $this->filterManager->applyFilter($binary, $filter, [ + return $this->filterManager->applyFilter($binary, $filter, array( 'filters' => $runtimeFilters, - ]); + )); } catch (NonExistingFilterException $e) { $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $path, $e->getMessage()); From 4bce009f73c55659143d1c731709aed78b435e19 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 14:35:35 +0200 Subject: [PATCH 11/20] CS fixes of docblocks --- Controller/ImagineController.php | 18 +++++++-------- Service/FilterService.php | 39 ++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Controller/ImagineController.php b/Controller/ImagineController.php index d476d9fda..daa4e0c3d 100644 --- a/Controller/ImagineController.php +++ b/Controller/ImagineController.php @@ -40,8 +40,8 @@ class ImagineController private $signer; /** - * @param FilterService $filterService - * @param DataManager $dataManager + * @param FilterService $filterService + * @param DataManager $dataManager * @param SignerInterface $signer */ public function __construct(FilterService $filterService, DataManager $dataManager, SignerInterface $signer) @@ -58,9 +58,9 @@ public function __construct(FilterService $filterService, DataManager $dataManag * The resulting image is cached so subsequent requests will redirect to the cached image instead applying the * filter and storing the image again. * - * @param \Symfony\Component\HttpFoundation\Request $request - * @param string $path - * @param string $filter + * @param Request $request + * @param string $path + * @param string $filter * * @throws \RuntimeException * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException @@ -96,10 +96,10 @@ public function filterAction(Request $request, $path, $filter) * The resulting image is cached so subsequent requests will redirect to the cached image instead applying the * filter and storing the image again. * - * @param \Symfony\Component\HttpFoundation\Request $request - * @param string $hash - * @param string $path - * @param string $filter + * @param Request $request + * @param string $hash + * @param string $path + * @param string $filter * * @throws \RuntimeException * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException diff --git a/Service/FilterService.php b/Service/FilterService.php index 992e3de62..113d111ca 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -41,10 +41,9 @@ class FilterService private $logger; /** - * FilterService constructor. - * @param DataManager $dataManager - * @param FilterManager $filterManager - * @param CacheManager $cacheManager + * @param DataManager $dataManager + * @param FilterManager $filterManager + * @param CacheManager $cacheManager * @param LoggerInterface $logger */ public function __construct( @@ -60,9 +59,10 @@ public function __construct( } /** - * @param string $path - * @param string $filter - * @param string $resolver + * @param string $path + * @param string $filter + * @param string|null $resolver + * * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException */ @@ -86,10 +86,11 @@ public function createFilteredImage($path, $filter, $resolver = null) } /** - * @param string $path - * @param string $filter - * @param string $resolver - * @param array $runtimeFilters + * @param string $path + * @param string $filter + * @param array $runtimeFilters + * @param string|null $resolver + * * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException */ @@ -118,6 +119,7 @@ public function createFilteredImageWithRuntimeFilters($path, $filter, array $run * @param string $path * @param string $filter * @param string $resolver + * * @return string */ public function getUrlOfFilteredImage($path, $filter, $resolver = null) @@ -126,10 +128,11 @@ public function getUrlOfFilteredImage($path, $filter, $resolver = null) } /** - * @param string $path - * @param string $filter - * @param string $resolver - * @param array $runtimeFilters + * @param string $path + * @param string $filter + * @param array $runtimeFilters + * @param string|null $resolver + * * @return string */ public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = array(), $resolver = null) @@ -141,9 +144,11 @@ public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $r /** * @param string $path * @param string $filter - * @param array|null $runtimeFilters - * @return \Liip\ImagineBundle\Binary\BinaryInterface + * @param array $runtimeFilters + * * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + + * @return \Liip\ImagineBundle\Binary\BinaryInterface */ private function createFilteredBinary($path, $filter, array $runtimeFilters = array()) { From 9bf0ce80199cfd5ea78372415512a6f747973867 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 14:39:05 +0200 Subject: [PATCH 12/20] No longer use unused classes in ResolveCacheCommand --- Command/ResolveCacheCommand.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Command/ResolveCacheCommand.php b/Command/ResolveCacheCommand.php index 7050297fd..04ba1eaef 100644 --- a/Command/ResolveCacheCommand.php +++ b/Command/ResolveCacheCommand.php @@ -11,8 +11,6 @@ namespace Liip\ImagineBundle\Command; -use Liip\ImagineBundle\Imagine\Cache\CacheManager; -use Liip\ImagineBundle\Imagine\Data\DataManager; use Liip\ImagineBundle\Imagine\Filter\FilterManager; use Liip\ImagineBundle\Service\FilterService; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; From 5122ca8ff102f11f4e2222d77fef238a4a70a2b0 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 5 May 2017 14:43:05 +0200 Subject: [PATCH 13/20] Use short class names instead of FQCN in docblocks --- Controller/ImagineController.php | 14 +++++++------- Service/FilterService.php | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Controller/ImagineController.php b/Controller/ImagineController.php index daa4e0c3d..519bdce70 100644 --- a/Controller/ImagineController.php +++ b/Controller/ImagineController.php @@ -62,10 +62,10 @@ public function __construct(FilterService $filterService, DataManager $dataManag * @param string $path * @param string $filter * - * @throws \RuntimeException - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws RuntimeException + * @throws NotFoundHttpException * - * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @return RedirectResponse */ public function filterAction(Request $request, $path, $filter) { @@ -101,11 +101,11 @@ public function filterAction(Request $request, $path, $filter) * @param string $path * @param string $filter * - * @throws \RuntimeException - * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws RuntimeException + * @throws BadRequestHttpException + * @throws NotFoundHttpException * - * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @return RedirectResponse */ public function filterRuntimeAction(Request $request, $hash, $path, $filter) { diff --git a/Service/FilterService.php b/Service/FilterService.php index 113d111ca..fc667f228 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -11,6 +11,8 @@ namespace Liip\ImagineBundle\Service; +use Liip\ImagineBundle\Binary\BinaryInterface; +use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException; use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException; use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Data\DataManager; @@ -63,8 +65,8 @@ public function __construct( * @param string $filter * @param string|null $resolver * - * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException - * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + * @throws NotLoadableException + * @throws NonExistingFilterException */ public function createFilteredImage($path, $filter, $resolver = null) { @@ -91,8 +93,8 @@ public function createFilteredImage($path, $filter, $resolver = null) * @param array $runtimeFilters * @param string|null $resolver * - * @throws \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException - * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + * @throws NotLoadableException + * @throws NonExistingFilterException */ public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = array(), $resolver = null) { @@ -146,9 +148,9 @@ public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $r * @param string $filter * @param array $runtimeFilters * - * @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException + * @throws NonExistingFilterException - * @return \Liip\ImagineBundle\Binary\BinaryInterface + * @return BinaryInterface */ private function createFilteredBinary($path, $filter, array $runtimeFilters = array()) { From b60debc9779a988415a7a99da6f847ac5412fd8f Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Mon, 8 May 2017 21:47:21 +0200 Subject: [PATCH 14/20] Use short array syntax now that PHP5.3 support was dropped --- Service/FilterService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Service/FilterService.php b/Service/FilterService.php index fc667f228..7b881a319 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -96,7 +96,7 @@ public function createFilteredImage($path, $filter, $resolver = null) * @throws NotLoadableException * @throws NonExistingFilterException */ - public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = array(), $resolver = null) + public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) { $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); if ($this->cacheManager->isStored($runtimePath, $filter, $resolver)) { @@ -137,7 +137,7 @@ public function getUrlOfFilteredImage($path, $filter, $resolver = null) * * @return string */ - public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = array(), $resolver = null) + public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) { $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); return $this->cacheManager->resolve($runtimePath, $filter, $resolver); @@ -152,14 +152,14 @@ public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $r * @return BinaryInterface */ - private function createFilteredBinary($path, $filter, array $runtimeFilters = array()) + private function createFilteredBinary($path, $filter, array $runtimeFilters = []) { $binary = $this->dataManager->find($filter, $path); try { - return $this->filterManager->applyFilter($binary, $filter, array( + return $this->filterManager->applyFilter($binary, $filter, [ 'filters' => $runtimeFilters, - )); + ]); } catch (NonExistingFilterException $e) { $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $path, $e->getMessage()); From 05afc99e126d4f2f784db7dc44028605ca619c00 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Wed, 10 May 2017 22:23:13 +0200 Subject: [PATCH 15/20] Use FilterService in ResolveCacheProcessor --- Async/ResolveCacheProcessor.php | 36 +-- Resources/config/enqueue.xml | 3 +- Service/FilterService.php | 13 ++ Tests/Async/ResolveCacheProcessorTest.php | 271 +++++++++++++--------- 4 files changed, 184 insertions(+), 139 deletions(-) diff --git a/Async/ResolveCacheProcessor.php b/Async/ResolveCacheProcessor.php index edb7d467a..11121fd24 100644 --- a/Async/ResolveCacheProcessor.php +++ b/Async/ResolveCacheProcessor.php @@ -18,26 +18,20 @@ use Enqueue\Psr\PsrContext; use Enqueue\Psr\PsrMessage; use Enqueue\Psr\PsrProcessor; -use Liip\ImagineBundle\Imagine\Cache\CacheManager; -use Liip\ImagineBundle\Imagine\Data\DataManager; use Liip\ImagineBundle\Imagine\Filter\FilterManager; +use Liip\ImagineBundle\Service\FilterService; class ResolveCacheProcessor implements PsrProcessor, TopicSubscriberInterface, QueueSubscriberInterface { - /** - * @var CacheManager - */ - private $cacheManager; - /** * @var FilterManager */ private $filterManager; /** - * @var DataManager + * @var FilterService */ - private $dataManager; + private $filterService; /** * @var ProducerInterface @@ -45,20 +39,17 @@ class ResolveCacheProcessor implements PsrProcessor, TopicSubscriberInterface, Q private $producer; /** - * @param CacheManager $cacheManager * @param FilterManager $filterManager - * @param DataManager $dataManager + * @param FilterService $filterService * @param ProducerInterface $producer */ public function __construct( - CacheManager $cacheManager, FilterManager $filterManager, - DataManager $dataManager, + FilterService $filterService, ProducerInterface $producer ) { - $this->cacheManager = $cacheManager; $this->filterManager = $filterManager; - $this->dataManager = $dataManager; + $this->filterService = $filterService; $this->producer = $producer; } @@ -77,20 +68,13 @@ public function process(PsrMessage $psrMessage, PsrContext $psrContext) $path = $message->getPath(); $results = []; foreach ($filters as $filter) { - if ($this->cacheManager->isStored($path, $filter) && $message->isForce()) { - $this->cacheManager->remove($path, $filter); + if ($message->isForce()) { + $this->filterService->bustCache($path, $filter); } - if (false == $this->cacheManager->isStored($path, $filter)) { - $binary = $this->dataManager->find($filter, $path); - $this->cacheManager->store( - $this->filterManager->applyFilter($binary, $filter), - $path, - $filter - ); - } + $this->filterService->createFilteredImage($path, $filter); - $results[$filter] = $this->cacheManager->resolve($path, $filter); + $results[$filter] = $this->filterService->getUrlOfFilteredImage($path, $filter); } $this->producer->send(Topics::CACHE_RESOLVED, new CacheResolved($path, $results)); diff --git a/Resources/config/enqueue.xml b/Resources/config/enqueue.xml index fc5e04f0a..82c972b2f 100644 --- a/Resources/config/enqueue.xml +++ b/Resources/config/enqueue.xml @@ -5,9 +5,8 @@ - - + diff --git a/Service/FilterService.php b/Service/FilterService.php index 7b881a319..c2f309b5d 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -117,6 +117,19 @@ public function createFilteredImageWithRuntimeFilters($path, $filter, array $run ); } + /** + * @param string $path + * @param string $filter + */ + public function bustCache($path, $filter) + { + if (!$this->cacheManager->isStored($path, $filter)) { + return; + } + + $this->cacheManager->remove($path, $filter); + } + /** * @param string $path * @param string $filter diff --git a/Tests/Async/ResolveCacheProcessorTest.php b/Tests/Async/ResolveCacheProcessorTest.php index 5886132e2..70f530bd0 100644 --- a/Tests/Async/ResolveCacheProcessorTest.php +++ b/Tests/Async/ResolveCacheProcessorTest.php @@ -67,9 +67,8 @@ public function testShouldSubscribeToExpectedQueue() public function testCouldBeConstructedWithExpectedArguments() { new ResolveCacheProcessor( - $this->createCacheManagerMock(), $this->createFilterManagerMock(), - $this->createDataManagerMock(), + $this->createFilterServiceMock(), $this->createProducerMock() ); } @@ -77,9 +76,8 @@ public function testCouldBeConstructedWithExpectedArguments() public function testShouldRejectMessagesWithInvalidJsonBody() { $processor = new ResolveCacheProcessor( - $this->createCacheManagerMock(), $this->createFilterManagerMock(), - $this->createDataManagerMock(), + $this->createFilterServiceMock(), $this->createProducerMock() ); @@ -96,9 +94,8 @@ public function testShouldRejectMessagesWithInvalidJsonBody() public function testShouldRejectMessagesWithoutPass() { $processor = new ResolveCacheProcessor( - $this->createCacheManagerMock(), $this->createFilterManagerMock(), - $this->createDataManagerMock(), + $this->createFilterServiceMock(), $this->createProducerMock() ); @@ -112,71 +109,178 @@ public function testShouldRejectMessagesWithoutPass() $this->assertEquals('The message does not contain "path" but it is required.', $result->getReason()); } - public function testShouldResolveCacheIfNotStored() + public function testShouldCreateFilteredImage() { - $originalBinary = $this->createDummyBinary(); - $filteredBinary = $this->createDummyBinary(); + $filterName = 'fooFilter'; + $imagePath = 'theImagePath'; $filterManagerMock = $this->createFilterManagerMock(); $filterManagerMock ->expects($this->once()) ->method('getFilterConfiguration') ->willReturn(new FilterConfiguration(array( - 'fooFilter' => array('fooFilterConfig'), + $filterName => array('fooFilterConfig'), ))) ; + + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock + ->expects($this->once()) + ->method('createFilteredImage') + ->with($imagePath, $filterName); + + $processor = new ResolveCacheProcessor( + $filterManagerMock, + $filterServiceMock, + $this->createProducerMock() + ); + + $message = new NullMessage(); + $message->setBody(json_encode(['path' => $imagePath])); + + $result = $processor->process($message, new NullContext()); + + $this->assertEquals(Result::ACK, $result); + } + + public function testShouldCreateOneImagePerFilter() + { + $filterName1 = 'fooFilter'; + $filterName2 = 'barFilter'; + $imagePath = 'theImagePath'; + + $filterManagerMock = $this->createFilterManagerMock(); $filterManagerMock ->expects($this->once()) - ->method('applyFilter') - ->with($this->identicalTo($originalBinary), 'fooFilter') - ->willReturn($filteredBinary) + ->method('getFilterConfiguration') + ->willReturn(new FilterConfiguration(array( + $filterName1 => array('fooFilterConfig'), + $filterName2 => array('fooFilterConfig'), + ))) ; - $cacheManagerMock = $this->createCacheManagerMock(); - $cacheManagerMock - ->expects($this->atLeastOnce()) - ->method('isStored') - ->willReturn(false) - ; - $cacheManagerMock + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock + ->expects($this->exactly(2)) + ->method('createFilteredImage') + ->withConsecutive( + [$imagePath, $filterName1], + [$imagePath, $filterName2] + ); + + $processor = new ResolveCacheProcessor( + $filterManagerMock, + $filterServiceMock, + $this->createProducerMock() + ); + + $message = new NullMessage(); + $message->setBody(json_encode(['path' => $imagePath])); + + $result = $processor->process($message, new NullContext()); + + $this->assertEquals(Result::ACK, $result); + } + + public function testShouldOnlyCreateImageForRequestedFilter() + { + $relevantFilter = 'fooFilter'; + $imagePath = 'theImagePath'; + + $filterManagerMock = $this->createFilterManagerMock(); + $filterManagerMock + ->expects($this->never()) + ->method('getFilterConfiguration'); + + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock ->expects($this->once()) - ->method('store') - ->with( - $this->identicalTo($filteredBinary), - 'theImagePath', - 'fooFilter' - ) - ; - $cacheManagerMock + ->method('createFilteredImage') + ->with($imagePath, $relevantFilter); + + $processor = new ResolveCacheProcessor( + $filterManagerMock, + $filterServiceMock, + $this->createProducerMock() + ); + + $message = new NullMessage(); + $message->setBody(json_encode(['path' => $imagePath, 'filters' => [$relevantFilter]])); + + $result = $processor->process($message, new NullContext()); + + $this->assertEquals(Result::ACK, $result); + } + + public function testShouldCreateOneImagePerRequestedFilter() + { + $relevantFilter1 = 'fooFilter'; + $relevantFilter2 = 'fooFilter'; + $imagePath = 'theImagePath'; + + $filterManagerMock = $this->createFilterManagerMock(); + $filterManagerMock + ->expects($this->never()) + ->method('getFilterConfiguration'); + + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock + ->expects($this->exactly(2)) + ->method('createFilteredImage') + ->withConsecutive( + [$imagePath, $relevantFilter1], + [$imagePath, $relevantFilter2] + ); + + $processor = new ResolveCacheProcessor( + $filterManagerMock, + $filterServiceMock, + $this->createProducerMock() + ); + + $message = new NullMessage(); + $message->setBody(json_encode(['path' => $imagePath, 'filters' => [$relevantFilter1, $relevantFilter2]])); + + $result = $processor->process($message, new NullContext()); + + $this->assertEquals(Result::ACK, $result); + } + + public function testShouldBurstCacheWhenResolvingForced() + { + $filterName = 'fooFilter'; + $imagePath = 'theImagePath'; + + $filterManagerMock = $this->createFilterManagerMock(); + $filterManagerMock ->expects($this->once()) - ->method('resolve') - ->with('theImagePath', 'fooFilter') + ->method('getFilterConfiguration') + ->willReturn(new FilterConfiguration(array( + $filterName => array('fooFilterConfig'), + ))) ; - $dataManagerMock = $this->createDataManagerMock(); - $dataManagerMock + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock ->expects($this->once()) - ->method('find') - ->with('fooFilter', 'theImagePath') - ->willReturn($originalBinary) - ; + ->method('bustCache') + ->with($imagePath, $filterName); $processor = new ResolveCacheProcessor( - $cacheManagerMock, $filterManagerMock, - $dataManagerMock, + $filterServiceMock, $this->createProducerMock() ); $message = new NullMessage(); - $message->setBody('{"path": "theImagePath"}'); + $message->setBody(json_encode(['path' => $imagePath, 'force' => true])); $result = $processor->process($message, new NullContext()); $this->assertEquals(Result::ACK, $result); } - public function testShouldNotResolveCacheIfStoredAndNotForce() + public function testShouldNotBurstCacheWhenResolvingNotForced() { $filterManagerMock = $this->createFilterManagerMock(); $filterManagerMock @@ -186,43 +290,20 @@ public function testShouldNotResolveCacheIfStoredAndNotForce() 'fooFilter' => array('fooFilterConfig'), ))) ; - $filterManagerMock - ->expects($this->never()) - ->method('applyFilter') - ; - - $cacheManagerMock = $this->createCacheManagerMock(); - $cacheManagerMock - ->expects($this->atLeastOnce()) - ->method('isStored') - ->willReturn(true) - ; - $cacheManagerMock - ->expects($this->never()) - ->method('store') - ; - $cacheManagerMock - ->expects($this->once()) - ->method('resolve') - ->with('theImagePath', 'fooFilter') - ->willReturn('fooFilterUri') - ; - $dataManagerMock = $this->createDataManagerMock(); - $dataManagerMock + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock ->expects($this->never()) - ->method('find') - ; + ->method('bustCache'); $processor = new ResolveCacheProcessor( - $cacheManagerMock, $filterManagerMock, - $dataManagerMock, + $filterServiceMock, $this->createProducerMock() ); $message = new NullMessage(); - $message->setBody('{"path": "theImagePath"}'); + $message->setBody(json_encode(['path' => 'theImagePath'])); $result = $processor->process($message, new NullContext()); @@ -241,46 +322,23 @@ public function testShouldSendMessageOnSuccessResolve() 'bazFilter' => array('bazFilterConfig'), ))) ; - $filterManagerMock - ->expects($this->atLeastOnce()) - ->method('applyFilter') - ->willReturn($this->createDummyBinary()) - ; - $cacheManagerMock = $this->createCacheManagerMock(); - $cacheManagerMock - ->expects($this->atLeastOnce()) - ->method('isStored') - ->willReturn(false) - ; - $cacheManagerMock - ->expects($this->atLeastOnce()) - ->method('store') - ; - $cacheManagerMock - ->expects($this->atLeastOnce()) - ->method('resolve') - ->willReturnCallback(function ($path, $filter) { + $filterServiceMock = $this->createFilterServiceMock(); + $filterServiceMock + ->expects($this->exactly(3)) + ->method('getUrlOfFilteredImage') + ->willReturnCallback(function($path, $filter) { return $path.$filter.'Uri'; - }) - ; + }); - $dataManagerMock = $this->createDataManagerMock(); - $dataManagerMock - ->expects($this->atLeastOnce()) - ->method('find') - ->willReturn($this->createDummyBinary()) - ; - - $testCase = $this; $producerMock = $this->createProducerMock(); $producerMock ->expects($this->once()) ->method('send') ->with(Topics::CACHE_RESOLVED, $this->isInstanceOf('Liip\ImagineBundle\Async\CacheResolved')) - ->willReturnCallback(function ($topic, CacheResolved $message) use ($testCase) { - $testCase->assertEquals('theImagePath', $message->getPath()); - $testCase->assertEquals(array( + ->willReturnCallback(function ($topic, CacheResolved $message) { + $this->assertEquals('theImagePath', $message->getPath()); + $this->assertEquals(array( 'fooFilter' => 'theImagePathfooFilterUri', 'barFilter' => 'theImagePathbarFilterUri', 'bazFilter' => 'theImagePathbazFilterUri', @@ -288,14 +346,13 @@ public function testShouldSendMessageOnSuccessResolve() }); $processor = new ResolveCacheProcessor( - $cacheManagerMock, $filterManagerMock, - $dataManagerMock, + $filterServiceMock, $producerMock ); $message = new NullMessage(); - $message->setBody('{"path": "theImagePath"}'); + $message->setBody(json_encode(['path' => 'theImagePath'])); $result = $processor->process($message, new NullContext()); @@ -309,12 +366,4 @@ private function createProducerMock() { return $this->createMock(ProducerInterface::class); } - - /** - * @return Binary - */ - private function createDummyBinary() - { - return new Binary('theContent', 'image/png', 'png'); - } } From a8cb68d3d1b946d972429bcba29d609041c6f5d0 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Sat, 20 May 2017 17:40:35 +0200 Subject: [PATCH 16/20] Create filtered image in getUrlOf... methods in FilterService By coupling the creation of the filtered image to resolvig the URL of the resolving image the use case of requesting the URL of a filtered image that has not been created yet (temporal coupling issue) is no longer possible. The current implementation breaks CQS, but this is not as bad as the previous temporal coupling. --- Async/ResolveCacheProcessor.php | 2 - Command/ResolveCacheCommand.php | 2 - Controller/ImagineController.php | 4 -- Service/FilterService.php | 72 ++++++++--------------- Tests/Async/ResolveCacheProcessorTest.php | 8 +-- 5 files changed, 28 insertions(+), 60 deletions(-) diff --git a/Async/ResolveCacheProcessor.php b/Async/ResolveCacheProcessor.php index 11121fd24..84d3a023b 100644 --- a/Async/ResolveCacheProcessor.php +++ b/Async/ResolveCacheProcessor.php @@ -72,8 +72,6 @@ public function process(PsrMessage $psrMessage, PsrContext $psrContext) $this->filterService->bustCache($path, $filter); } - $this->filterService->createFilteredImage($path, $filter); - $results[$filter] = $this->filterService->getUrlOfFilteredImage($path, $filter); } diff --git a/Command/ResolveCacheCommand.php b/Command/ResolveCacheCommand.php index 04ba1eaef..ae519dd57 100644 --- a/Command/ResolveCacheCommand.php +++ b/Command/ResolveCacheCommand.php @@ -74,8 +74,6 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($paths as $path) { foreach ($filters as $filter) { - $filterService->createFilteredImage($path, $filter); - $output->writeln($filterService->getUrlOfFilteredImage($path, $filter)); } } diff --git a/Controller/ImagineController.php b/Controller/ImagineController.php index 2b20b9f1f..ce47f7d73 100644 --- a/Controller/ImagineController.php +++ b/Controller/ImagineController.php @@ -73,8 +73,6 @@ public function filterAction(Request $request, $path, $filter) $resolver = $request->get('resolver'); try { - $this->filterService->createFilteredImage($path, $filter, $resolver); - return new RedirectResponse($this->filterService->getUrlOfFilteredImage($path, $filter, $resolver), 301); } catch (NotLoadableException $e) { if ($this->dataManager->getDefaultImageUrl($filter) !== null) { @@ -126,8 +124,6 @@ public function filterRuntimeAction(Request $request, $hash, $path, $filter) } try { - $this->filterService->createFilteredImageWithRuntimeFilters($path, $filter, $runtimeConfig, $resolver); - return new RedirectResponse($this->filterService->getUrlOfFilteredImageWithRuntimeFilters($path, $filter, $runtimeConfig, $resolver), 301); } catch (NotLoadableException $e) { if ($this->dataManager->getDefaultImageUrl($filter) !== null) { diff --git a/Service/FilterService.php b/Service/FilterService.php index c2f309b5d..6ea0a1f38 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -61,17 +61,29 @@ public function __construct( } /** - * @param string $path - * @param string $filter - * @param string|null $resolver + * @param string $path + * @param string $filter + */ + public function bustCache($path, $filter) + { + if (!$this->cacheManager->isStored($path, $filter)) { + return; + } + + $this->cacheManager->remove($path, $filter); + } + + /** + * @param string $path + * @param string $filter + * @param string $resolver * - * @throws NotLoadableException - * @throws NonExistingFilterException + * @return string */ - public function createFilteredImage($path, $filter, $resolver = null) + public function getUrlOfFilteredImage($path, $filter, $resolver = null) { if ($this->cacheManager->isStored($path, $filter, $resolver)) { - return; + return $this->cacheManager->resolve($path, $filter, $resolver); } $filteredBinary = $this->createFilteredBinary( @@ -85,6 +97,8 @@ public function createFilteredImage($path, $filter, $resolver = null) $filter, $resolver ); + + return $this->cacheManager->resolve($path, $filter, $resolver); } /** @@ -93,14 +107,13 @@ public function createFilteredImage($path, $filter, $resolver = null) * @param array $runtimeFilters * @param string|null $resolver * - * @throws NotLoadableException - * @throws NonExistingFilterException + * @return string */ - public function createFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) + public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) { $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); if ($this->cacheManager->isStored($runtimePath, $filter, $resolver)) { - return; + return $this->cacheManager->resolve($runtimePath, $filter, $resolver); } $filteredBinary = $this->createFilteredBinary( @@ -115,44 +128,7 @@ public function createFilteredImageWithRuntimeFilters($path, $filter, array $run $filter, $resolver ); - } - - /** - * @param string $path - * @param string $filter - */ - public function bustCache($path, $filter) - { - if (!$this->cacheManager->isStored($path, $filter)) { - return; - } - $this->cacheManager->remove($path, $filter); - } - - /** - * @param string $path - * @param string $filter - * @param string $resolver - * - * @return string - */ - public function getUrlOfFilteredImage($path, $filter, $resolver = null) - { - return $this->cacheManager->resolve($path, $filter, $resolver); - } - - /** - * @param string $path - * @param string $filter - * @param array $runtimeFilters - * @param string|null $resolver - * - * @return string - */ - public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null) - { - $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters); return $this->cacheManager->resolve($runtimePath, $filter, $resolver); } diff --git a/Tests/Async/ResolveCacheProcessorTest.php b/Tests/Async/ResolveCacheProcessorTest.php index 70f530bd0..0e2959635 100644 --- a/Tests/Async/ResolveCacheProcessorTest.php +++ b/Tests/Async/ResolveCacheProcessorTest.php @@ -126,7 +126,7 @@ public function testShouldCreateFilteredImage() $filterServiceMock = $this->createFilterServiceMock(); $filterServiceMock ->expects($this->once()) - ->method('createFilteredImage') + ->method('getUrlOfFilteredImage') ->with($imagePath, $filterName); $processor = new ResolveCacheProcessor( @@ -162,7 +162,7 @@ public function testShouldCreateOneImagePerFilter() $filterServiceMock = $this->createFilterServiceMock(); $filterServiceMock ->expects($this->exactly(2)) - ->method('createFilteredImage') + ->method('getUrlOfFilteredImage') ->withConsecutive( [$imagePath, $filterName1], [$imagePath, $filterName2] @@ -195,7 +195,7 @@ public function testShouldOnlyCreateImageForRequestedFilter() $filterServiceMock = $this->createFilterServiceMock(); $filterServiceMock ->expects($this->once()) - ->method('createFilteredImage') + ->method('getUrlOfFilteredImage') ->with($imagePath, $relevantFilter); $processor = new ResolveCacheProcessor( @@ -226,7 +226,7 @@ public function testShouldCreateOneImagePerRequestedFilter() $filterServiceMock = $this->createFilterServiceMock(); $filterServiceMock ->expects($this->exactly(2)) - ->method('createFilteredImage') + ->method('getUrlOfFilteredImage') ->withConsecutive( [$imagePath, $relevantFilter1], [$imagePath, $relevantFilter2] From fdd930202784741ec0a0a94752fca268a722c1c3 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Sat, 20 May 2017 17:49:25 +0200 Subject: [PATCH 17/20] Update README to reflect removal of FilterService::create... methods --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index b5b4fd20c..164e3fd96 100644 --- a/README.md +++ b/README.md @@ -329,7 +329,6 @@ class MyController extends Controller ->get('liip_imagine.service.filter'); // 1) Simple filter, OR - $imagine->createFilteredImage('uploads/foo.jpg', 'my_thumb'); $resourcePath = $imagine->getUrlOfFilteredImage('uploads/foo.jpg', 'my_thumb'); // 2) Runtime configuration @@ -338,11 +337,6 @@ class MyController extends Controller 'size' => [200, 200] ], ]; - $imagine->createFilteredImageWithRuntimeFilters( - 'uploads/foo.jpg', - 'my_thumb', - $runtimeConfig - ); $resourcePath = $imagine->getUrlOfFilteredImageWithRuntimeFilters( 'uploads/foo.jpg', 'my_thumb', From edd673e9abb7d0c92c5692f6fb0ed642e2b02502 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Sat, 20 May 2017 17:51:22 +0200 Subject: [PATCH 18/20] Use short ternary syntax for logger in FilterService --- Service/FilterService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/FilterService.php b/Service/FilterService.php index 6ea0a1f38..f58c65b84 100644 --- a/Service/FilterService.php +++ b/Service/FilterService.php @@ -57,7 +57,7 @@ public function __construct( $this->dataManager = $dataManager; $this->filterManager = $filterManager; $this->cacheManager = $cacheManager; - $this->logger = $logger ? $logger : new NullLogger(); + $this->logger = $logger ?: new NullLogger(); } /** From fe47041801561c5e106fd3ca2643731f7d09ce81 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Thu, 12 Oct 2017 21:26:09 +0200 Subject: [PATCH 19/20] No longer require @dev for enqueue-bundle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8f6ecf14f..53eb73369 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "aws/aws-sdk-php": "~2.4", "doctrine/cache": "~1.1", "doctrine/orm": "~2.3", - "enqueue/enqueue-bundle": "^0.7.0@dev", + "enqueue/enqueue-bundle": "^0.7.0", "friendsofphp/php-cs-fixer": "~1.0", "league/flysystem": "~1.0", "phpunit/phpunit": "~5.0", From 270c250c9277b1f13d2eaf54bd4c5becb97bd7f8 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Thu, 12 Oct 2017 21:31:49 +0200 Subject: [PATCH 20/20] Require enqueue-bundle ^0.7, not ^0.7.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 53eb73369..655519dc6 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "aws/aws-sdk-php": "~2.4", "doctrine/cache": "~1.1", "doctrine/orm": "~2.3", - "enqueue/enqueue-bundle": "^0.7.0", + "enqueue/enqueue-bundle": "^0.7", "friendsofphp/php-cs-fixer": "~1.0", "league/flysystem": "~1.0", "phpunit/phpunit": "~5.0",