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

[Symfony] Bug fixes and deprecation cleanup for Symfony 3.3 #860

Merged
merged 1 commit into from
Jan 27, 2017
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
57 changes: 57 additions & 0 deletions DependencyInjection/Factory/Loader/AbstractLoaderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Liip\ImagineBundle\DependencyInjection\Factory\Loader;

use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

abstract class AbstractLoaderFactory implements LoaderFactoryInterface
{
/**
* @var string
*/
protected static $namePrefix = 'liip_imagine.binary.loader';

/**
* @return ChildDefinition|DefinitionDecorator
*/
final protected function getChildLoaderDefinition()
{
$parent = sprintf('%s.prototype.%s', static::$namePrefix, $this->getName());

return class_exists('\Symfony\Component\DependencyInjection\ChildDefinition') ?
new ChildDefinition($parent) : new DefinitionDecorator($parent);
}

/**
* @param string $name
* @param Definition $definition
* @param ContainerBuilder $container
*
* @return string
*/
final protected function setTaggedLoaderDefinition($name, Definition $definition, ContainerBuilder $container)
{
$definition->addTag(static::$namePrefix, array(
'loader' => $name,
));

$container->setDefinition(
$id = sprintf('%s.%s', static::$namePrefix, $name),
$definition
);

return $id;
}
}
15 changes: 4 additions & 11 deletions DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,18 @@

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

class FileSystemLoaderFactory implements LoaderFactoryInterface
class FileSystemLoaderFactory extends AbstractLoaderFactory
{
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.filesystem');
$loaderDefinition->replaceArgument(2, $config['data_root']);
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => $loaderName,
));
$loaderId = 'liip_imagine.binary.loader.'.$loaderName;
$definition = $this->getChildLoaderDefinition();
$definition->replaceArgument(2, $config['data_root']);

$container->setDefinition($loaderId, $loaderDefinition);

return $loaderId;
return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
}

/**
Expand Down
15 changes: 4 additions & 11 deletions DependencyInjection/Factory/Loader/FlysystemLoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;

class FlysystemLoaderFactory implements LoaderFactoryInterface
class FlysystemLoaderFactory extends AbstractLoaderFactory
{
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.flysystem');
$loaderDefinition->replaceArgument(1, new Reference($config['filesystem_service']));
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => $loaderName,
));
$loaderId = 'liip_imagine.binary.loader.'.$loaderName;
$definition = $this->getChildLoaderDefinition();
$definition->replaceArgument(1, new Reference($config['filesystem_service']));

$container->setDefinition($loaderId, $loaderDefinition);

return $loaderId;
return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
}

/**
Expand Down
17 changes: 5 additions & 12 deletions DependencyInjection/Factory/Loader/StreamLoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

class StreamLoaderFactory implements LoaderFactoryInterface
class StreamLoaderFactory extends AbstractLoaderFactory
{
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $loaderName, array $config)
{
$loaderDefinition = new DefinitionDecorator('liip_imagine.binary.loader.prototype.stream');
$loaderDefinition->replaceArgument(0, $config['wrapper']);
$loaderDefinition->replaceArgument(1, $config['context']);
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => $loaderName,
));
$loaderId = 'liip_imagine.binary.loader.'.$loaderName;
$definition = $this->getChildLoaderDefinition();
$definition->replaceArgument(0, $config['wrapper']);
$definition->replaceArgument(1, $config['context']);

$container->setDefinition($loaderId, $loaderDefinition);

return $loaderId;
return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
}

/**
Expand Down
29 changes: 29 additions & 0 deletions Tests/DependencyInjection/Factory/FactoryTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory;

use Symfony\Component\DependencyInjection\Definition;

abstract class FactoryTestCase extends \Phpunit_Framework_TestCase
{
/**
* @param Definition $definition
*/
protected function assertInstanceOfChildDefinition(Definition $definition)
{
$expected = class_exists('\Symfony\Component\DependencyInjection\ChildDefinition') ?
'\Symfony\Component\DependencyInjection\ChildDefinition' :
'\Symfony\Component\DependencyInjection\DefinitionDecorator';

$this->assertInstanceOf($expected, $definition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Loader;

use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory;
use Liip\ImagineBundle\Tests\DependencyInjection\Factory\FactoryTestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @covers \Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory<extended>
*/
class FileSystemLoaderFactoryTest extends \Phpunit_Framework_TestCase
class FileSystemLoaderFactoryTest extends FactoryTestCase
{
public function testImplementsLoaderFactoryInterface()
{
Expand All @@ -46,14 +47,15 @@ public function testCreateLoaderDefinitionOnCreate()

$loader = new FileSystemLoaderFactory();

$loader->create($container, 'theLoaderName', array(
$loader->create($container, 'the_loader_name', array(
'data_root' => 'theDataRoot',
));

$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername'));
$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.the_loader_name'));

$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition);
$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.the_loader_name');

$this->assertInstanceOfChildDefinition($loaderDefinition);
$this->assertEquals('liip_imagine.binary.loader.prototype.filesystem', $loaderDefinition->getParent());

$this->assertEquals('theDataRoot', $loaderDefinition->getArgument(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public function testCreateLoaderDefinitionOnCreate()

$loader = new FlysystemLoaderFactory();

$loader->create($container, 'theLoaderName', array(
$loader->create($container, 'the_loader_name', array(
'filesystem_service' => 'flyfilesystemservice',
));

$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername'));
$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.the_loader_name'));

$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername');
$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.the_loader_name');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition);
$this->assertEquals('liip_imagine.binary.loader.prototype.flysystem', $loaderDefinition->getParent());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function testCreateLoaderDefinitionOnCreate()

$loader = new StreamLoaderFactory();

$loader->create($container, 'theLoaderName', array(
$loader->create($container, 'the_loader_name', array(
'wrapper' => 'theWrapper',
'context' => 'theContext',
));

$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername'));
$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.the_loader_name'));

$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername');
$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.the_loader_name');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition);
$this->assertEquals('liip_imagine.binary.loader.prototype.stream', $loaderDefinition->getParent());

Expand Down
Loading