Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to Symfony5 #1256

Merged
merged 14 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ matrix:
- php: '7.1'
env:
- SYMFONY_VERSION=3.4.*
- php: '7.1'
env:
- SYMFONY_VERSION=4.2.*
- php: '7.1'
env:
- SYMFONY_VERSION=4.3.*
Expand Down
53 changes: 53 additions & 0 deletions DependencyInjection/Compiler/NonFunctionalFilterExceptionPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Liip\ImagineBundle\DependencyInjection\Compiler;

use Liip\ImagineBundle\Imagine\Filter\Loader\NonFunctionalPasteFilterLoader;
use Liip\ImagineBundle\Imagine\Filter\Loader\NonFunctionalWatermarkFilterLoader;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* For transitioning from Symfony 4 to Symfony 5 with the removal
* of the kernel.root_dir parameter.
*/
class NonFunctionalFilterExceptionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$canFiltersStillFunction = $container->hasParameter('kernel.root_dir');
$throwWarning = function(string $filterName) use ($canFiltersStillFunction) {
$message = sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really clear error message! Love this solution :)

'The "%s" filter %s in Symfony 5.0. Please use "%s_image" and adapt the "image" option to be relative to the "%%kernel.project_dir%%" instead of "%%kernel.root_dir%%".',
$filterName,
$canFiltersStillFunction ? 'is deprecated and will not work' : 'no longer works',
$filterName
);

if ($canFiltersStillFunction) {
@trigger_error($message, E_USER_DEPRECATED);
} else {
throw new \InvalidArgumentException($message);
}
};

$filterSets = $container->getParameter('liip_imagine.filter_sets');
foreach ($filterSets as $filterSet) {
foreach ($filterSet['filters'] as $filterName => $filter) {
if ($filterName === 'paste') {
$throwWarning('paste');
}

if ($filterName === 'watermark') {
$throwWarning('watermark');
}
}
}

// remove the definitions entirely if kernel.root_dir does not exist
if (!$canFiltersStillFunction) {
$container->removeDefinition('liip_imagine.filter.loader.watermark');
$container->removeDefinition('liip_imagine.filter.loader.paste');
}
}
}
8 changes: 4 additions & 4 deletions Imagine/Filter/Loader/PasteFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class PasteFilterLoader implements LoaderInterface
/**
* @var string
*/
protected $rootPath;
protected $projectDir;

public function __construct(ImagineInterface $imagine, $rootPath)
public function __construct(ImagineInterface $imagine, $projectDir)
{
$this->imagine = $imagine;
$this->rootPath = $rootPath;
$this->projectDir = $projectDir;
}

/**
Expand All @@ -46,7 +46,7 @@ public function load(ImageInterface $image, array $options = [])
$x = isset($options['start'][0]) ? $options['start'][0] : null;
$y = isset($options['start'][1]) ? $options['start'][1] : null;

$destImage = $this->imagine->open($this->rootPath.'/'.$options['image']);
$destImage = $this->imagine->open($this->projectDir.'/'.$options['image']);

return $image->paste($destImage, new Point($x, $y));
}
Expand Down
8 changes: 4 additions & 4 deletions Imagine/Filter/Loader/WatermarkFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class WatermarkFilterLoader implements LoaderInterface
/**
* @var string
*/
protected $rootPath;
protected $projectDir;

public function __construct(ImagineInterface $imagine, $rootPath)
public function __construct(ImagineInterface $imagine, $projectDir)
{
$this->imagine = $imagine;
$this->rootPath = $rootPath;
$this->projectDir = $projectDir;
}

/**
Expand All @@ -53,7 +53,7 @@ public function load(ImageInterface $image, array $options = [])
$options['size'] = mb_substr($options['size'], 0, -1) / 100;
}

$watermark = $this->imagine->open($this->rootPath.'/'.$options['image']);
$watermark = $this->imagine->open($this->projectDir.'/'.$options['image']);

$size = $image->getSize();
$watermarkSize = $watermark->getSize();
Expand Down
2 changes: 2 additions & 0 deletions LiipImagineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\MetadataReaderCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\NonFunctionalFilterExceptionPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\PostProcessorsCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\ResolversCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\ChainLoaderFactory;
Expand All @@ -39,6 +40,7 @@ public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new NonFunctionalFilterExceptionPass());
$container->addCompilerPass(new DriverCompilerPass());
$container->addCompilerPass(new LoadersCompilerPass());
$container->addCompilerPass(new FiltersCompilerPass());
Expand Down
16 changes: 15 additions & 1 deletion Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,31 @@
<tag name="liip_imagine.filter.loader" loader="grayscale" />
</service>

<service id="liip_imagine.filter.loader.paste_image" class="Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader">
<tag name="liip_imagine.filter.loader" loader="paste_image" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.project_dir%</argument>
</service>

<!-- deprecated -->
<!-- not officially deprecated because they are still injected and appear "used" -->
<service id="liip_imagine.filter.loader.paste" class="Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader">
<tag name="liip_imagine.filter.loader" loader="paste" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.root_dir%</argument>
</service>

<service id="liip_imagine.filter.loader.watermark" class="Liip\ImagineBundle\Imagine\Filter\Loader\WatermarkFilterLoader">
<tag name="liip_imagine.filter.loader" loader="watermark" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.root_dir%</argument>
</service>
<!-- end deprecated -->

<service id="liip_imagine.filter.loader.watermark_image" class="Liip\ImagineBundle\Imagine\Filter\Loader\WatermarkFilterLoader">
<tag name="liip_imagine.filter.loader" loader="watermark_image" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.project_dir%</argument>
</service>

<service id="liip_imagine.filter.loader.background" class="Liip\ImagineBundle\Imagine\Filter\Loader\BackgroundFilterLoader">
<tag name="liip_imagine.filter.loader" loader="background" />
Expand Down
12 changes: 6 additions & 6 deletions Resources/doc/filters/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Example configuration:
Watermark
---------

The built-in ``watermark`` filter adds a watermark to an existing image
The built-in ``watermark_image`` filter adds a watermark to an existing image
(which includes creating and merging image operations). This
filter exposes a number of `watermark options`_ which may be used
to configure its behavior.
Expand All @@ -181,11 +181,11 @@ Example configuration:
my_watermark_filter:
filters:

# use and setup the "watermark" filter
watermark:
# use and setup the "watermark_image" filter
watermark_image:

# path to the watermark file (prepended with "%kernel.root_dir%")
image: Resources/data/watermark.png
# path to the watermark file (prepended with "%kernel.project_dir%")
image: assets/watermark.png

# size of the water mark relative to the input image
size: 0.5
Expand All @@ -199,7 +199,7 @@ Watermark Options

:strong:`image:` ``string``
Sets the location of the watermark image. The value of this option is prepended
with the resolved value of the ``%kernel.root_dir%`` parameter.
with the resolved value of the ``%kernel.project_dir%`` parameter.

:strong:`size:` ``float``
Sets the size of the watermark as a relative ration, relative to the original
Expand Down
4 changes: 2 additions & 2 deletions Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class AbstractTest extends TestCase
*/
protected $temporaryPath;

protected function setUp()
protected function setUp(): void
{
$this->fixturesPath = realpath(__DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$this->temporaryPath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'liip_imagine_test';
Expand All @@ -64,7 +64,7 @@ protected function setUp()
$this->filesystem->mkdir($this->temporaryPath);
}

protected function tearDown()
protected function tearDown(): void
{
if (!$this->filesystem) {
return;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/CacheResolvedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class CacheResolvedTest extends TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/ResolveCacheProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
class ResolveCacheProcessorTest extends AbstractTest
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/ResolveCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class ResolveCacheTest extends TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Binary/Loader/AbstractDoctrineLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AbstractDoctrineLoaderTest extends TestCase
*/
private $loader;

public function setUp()
public function setUp(): void
{
if (!interface_exists(ObjectManager::class)) {
$this->markTestSkipped('Requires the doctrine/orm package.');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Binary/Loader/FlysystemLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FlysystemLoaderTest extends AbstractTest
{
private $flyFilesystem;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Config/FilterSetBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FilterSetBuilderTest extends TestCase
*/
private $model;

protected function setUp()
protected function setUp(): void
{
$this->filterSetFactoryMock = $this->createMock(StackFactoryInterface::class);
$this->filterFactoryCollectionMock = $this->createMock(FilterFactoryCollection::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class FlysystemLoaderFactoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class FlysystemResolverFactoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
4 changes: 0 additions & 4 deletions Tests/Events/CacheResolveEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
*/
class CacheResolveEventTest extends TestCase
{
protected function setUp()
{
}

public function testShouldAllowSetPathInConstruct(): void
{
$event = new CacheResolveEvent('default_path', 'default_filter');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Form/Type/ImageTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class ImageTypeTest extends AbstractTest
{
protected function setUp()
protected function setUp(): void
{
if (!class_exists(AbstractType::class)) {
$this->markTestSkipped('Requires the symfony/form package.');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/AbstractSetupWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AbstractSetupWebTestCase extends AbstractWebTestCase
*/
protected $cacheRoot;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 2 additions & 0 deletions Tests/Imagine/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ private function getDispatcherCallbackWithBC(EventDispatcherInterface $dispatche
} else {
$callable($name, $event);
}

return $event;
};
}

Expand Down
9 changes: 7 additions & 2 deletions Tests/Imagine/Cache/Resolver/CacheResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CacheResolverTest extends AbstractTest
protected $path = 'MadCat2.jpeg';
protected $webPath = '/media/cache/thumbnail/MadCat2.jpeg';

protected function setUp()
protected function setUp(): void
{
if (!class_exists(ArrayCache::class)) {
$this->markTestSkipped('Requires the doctrine/cache package.');
Expand Down Expand Up @@ -194,7 +194,12 @@ public function testRemoveAllFilterCacheOnRemove(): void
*/
private function getCacheEntries(ArrayCache $cache): array
{
$cacheEntries = $this->readAttribute($cache, 'data');
$reflector = new \ReflectionObject($cache);
$attribute = $reflector->getProperty('data');
$attribute->setAccessible(true);
$cacheEntries = $attribute->getValue($cache);
$attribute->setAccessible(false);

unset($cacheEntries['DoctrineNamespaceCacheKey[]']);

return $cacheEntries;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Imagine/Cache/Resolver/FlysystemResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class FlysystemResolverTest extends AbstractTest
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Imagine/Cache/Resolver/ProxyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProxyResolverTest extends AbstractTest
*/
private $resolver;

public function setUp()
public function setUp(): void
{
$this->primaryResolver = $this->createObjectMock(ResolverInterface::class);
$this->resolver = new ProxyResolver($this->primaryResolver, ['http://images.example.com']);
Expand Down
Loading