Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[config] Fix default loader not found bug.

  • Loading branch information...
commit d896c23b24c9c91a126a7fa99bf2cf0d71a108fc 1 parent 2f9025e
@makasim makasim authored
View
26 DependencyInjection/Compiler/FiltersCompilerPass.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Liip\ImagineBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
+
+class FiltersCompilerPass implements CompilerPassInterface
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function process(ContainerBuilder $container)
+ {
+ $tags = $container->findTaggedServiceIds('liip_imagine.filter.loader');
+
+ if (count($tags) > 0 && $container->hasDefinition('liip_imagine.filter.manager')) {
+ $manager = $container->getDefinition('liip_imagine.filter.manager');
+
+ foreach ($tags as $id => $tag) {
+ $manager->addMethodCall('addLoader', array($tag[0]['loader'], new Reference($id)));
+ }
+ }
+ }
+}
View
23 DependencyInjection/Compiler/LoadersCompilerPass.php
@@ -8,18 +8,11 @@
class LoadersCompilerPass implements CompilerPassInterface
{
+ /**
+ * {@inheritDoc}
+ */
public function process(ContainerBuilder $container)
{
- $tags = $container->findTaggedServiceIds('liip_imagine.filter.loader');
-
- if (count($tags) > 0 && $container->hasDefinition('liip_imagine.filter.manager')) {
- $manager = $container->getDefinition('liip_imagine.filter.manager');
-
- foreach ($tags as $id => $tag) {
- $manager->addMethodCall('addLoader', array($tag[0]['loader'], new Reference($id)));
- }
- }
-
$tags = $container->findTaggedServiceIds('liip_imagine.binary.loader');
if (count($tags) > 0 && $container->hasDefinition('liip_imagine.data.manager')) {
@@ -29,15 +22,5 @@ public function process(ContainerBuilder $container)
$manager->addMethodCall('addLoader', array($tag[0]['loader'], new Reference($id)));
}
}
-
- $tags = $container->findTaggedServiceIds('liip_imagine.cache.resolver');
-
- if (count($tags) > 0 && $container->hasDefinition('liip_imagine.cache.manager')) {
- $manager = $container->getDefinition('liip_imagine.cache.manager');
-
- foreach ($tags as $id => $tag) {
- $manager->addMethodCall('addResolver', array($tag[0]['resolver'], new Reference($id)));
- }
- }
}
}
View
26 DependencyInjection/Compiler/ResolversCompilerPass.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Liip\ImagineBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
+
+class ResolversCompilerPass implements CompilerPassInterface
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function process(ContainerBuilder $container)
+ {
+ $tags = $container->findTaggedServiceIds('liip_imagine.cache.resolver');
+
+ if (count($tags) > 0 && $container->hasDefinition('liip_imagine.cache.manager')) {
+ $manager = $container->getDefinition('liip_imagine.cache.manager');
+
+ foreach ($tags as $id => $tag) {
+ $manager->addMethodCall('addResolver', array($tag[0]['resolver'], new Reference($id)));
+ }
+ }
+ }
+}
View
60 DependencyInjection/Configuration.php
@@ -41,44 +41,52 @@ public function getConfigTreeBuilder()
$resolversPrototypeNode = $rootNode
->children()
->arrayNode('resolvers')
- ->beforeNormalization()
- ->ifTrue(function ($v) { return !is_array($v) || (is_array($v) && !array_key_exists('default', $v)); })
- ->then(function ($v) {
- if (false == is_array($v)) {
- $v = array();
- }
-
- $v['default'] = array('web_path' => null);
-
- return $v;
- })
- ->end()
- ->useAttributeAsKey('name')
- ->prototype('array')
+ ->useAttributeAsKey('name')
+ ->prototype('array')
;
$this->addResolversSections($resolversPrototypeNode);
$loadersPrototypeNode = $rootNode
->children()
->arrayNode('loaders')
- ->beforeNormalization()
- ->ifTrue(function ($v) { return !is_array($v) || (is_array($v) && !array_key_exists('default', $v)); })
- ->then(function ($v) {
- if (false == is_array($v)) {
- $v = array();
- }
-
- $v['default'] = array('filesystem' => null);
-
- return $v;
- })
- ->end()
->useAttributeAsKey('name')
->prototype('array')
;
$this->addLoadersSections($loadersPrototypeNode);
$rootNode
+ ->beforeNormalization()
+ ->ifTrue(function ($v) {
+ return
+ empty($v['loaders']) ||
+ !array_key_exists('default', $v['loaders']) ||
+ empty($v['resolvers']) ||
+ !array_key_exists('default', $v['resolvers'])
+ ;
+ })
+ ->then(function ($v) {
+ if (false == array_key_exists('loaders', $v)) {
+ $v['loaders'] = array();
+ }
+
+ if (false == array_key_exists('default', $v['loaders'])) {
+ $v['loaders']['default'] = array('filesystem' => null);
+ }
+
+ if (false == array_key_exists('resolvers', $v)) {
+ $v['resolvers'] = array();
+ }
+
+ if (false == array_key_exists('default', $v['resolvers'])) {
+ $v['resolvers']['default'] = array('web_path' => null);
+ }
+
+ return $v;
+ })
+ ->end()
+ ;
+
+ $rootNode
->fixXmlConfig('filter_set', 'filter_sets')
->children()
->scalarNode('driver')->defaultValue('gd')
View
1  DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php
@@ -38,7 +38,6 @@ public function getName()
public function addConfiguration(ArrayNodeDefinition $builder)
{
$builder
- ->addDefaultsIfNotSet()
->children()
->scalarNode('data_root')->defaultValue('%kernel.root_dir%/../web')->cannotBeEmpty()->end()
->end()
View
1  DependencyInjection/Factory/Loader/StreamLoaderFactory.php
@@ -39,7 +39,6 @@ public function getName()
public function addConfiguration(ArrayNodeDefinition $builder)
{
$builder
- ->addDefaultsIfNotSet()
->children()
->scalarNode('wrapper')->isRequired()->cannotBeEmpty()->end()
->scalarNode('context')->defaultValue(null)->end()
View
1  DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php
@@ -67,7 +67,6 @@ public function getName()
public function addConfiguration(ArrayNodeDefinition $builder)
{
$builder
- ->addDefaultsIfNotSet()
->children()
->scalarNode('bucket')->isRequired()->cannotBeEmpty()->end()
->scalarNode('cache')->defaultValue(false)->end()
View
1  DependencyInjection/Factory/Resolver/WebPathResolverFactory.php
@@ -40,7 +40,6 @@ public function getName()
public function addConfiguration(ArrayNodeDefinition $builder)
{
$builder
- ->addDefaultsIfNotSet()
->children()
->scalarNode('web_root')->defaultValue('%kernel.root_dir%/../web')->cannotBeEmpty()->end()
->scalarNode('cache_prefix')->defaultValue('media/cache')->cannotBeEmpty()->end()
View
7 Imagine/Cache/CacheManager.php
@@ -84,12 +84,13 @@ protected function getResolver($filter)
{
$config = $this->filterConfig->get($filter);
- $resolverName = empty($config['cache'])
- ? $this->defaultResolver : $config['cache'];
+ $resolverName = empty($config['cache']) ? $this->defaultResolver : $config['cache'];
if (!isset($this->resolvers[$resolverName])) {
throw new \OutOfBoundsException(sprintf(
- 'Could not find resolver for "%s" filter type', $filter
+ 'Could not find resolver "%s" for "%s" filter type',
+ $resolverName,
+ $filter
));
}
View
11 Imagine/Data/DataManager.php
@@ -72,20 +72,21 @@ public function addLoader($filter, LoaderInterface $loader)
*
* @param string $filter
*
- * @return LoaderInterface
- *
* @throws \InvalidArgumentException
+ *
+ * @return LoaderInterface
*/
public function getLoader($filter)
{
$config = $this->filterConfig->get($filter);
- $loaderName = empty($config['data_loader'])
- ? $this->defaultLoader : $config['data_loader'];
+ $loaderName = empty($config['data_loader']) ? $this->defaultLoader : $config['data_loader'];
if (!isset($this->loaders[$loaderName])) {
throw new \InvalidArgumentException(sprintf(
- 'Could not find data loader for "%s" filter type', $filter
+ 'Could not find data loader "%s" for "%s" filter type',
+ $loaderName,
+ $filter
));
}
View
6 LiipImagineBundle.php
@@ -2,7 +2,9 @@
namespace Liip\ImagineBundle;
+use Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass;
+use Liip\ImagineBundle\DependencyInjection\Compiler\ResolversCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory;
@@ -20,7 +22,9 @@ public function build(ContainerBuilder $container)
{
parent::build($container);
- $container->addCompilerPass(new LoadersCompilerPass());
+ $container->addCompilerPass(new LoadersCompilerPass);
+ $container->addCompilerPass(new FiltersCompilerPass);
+ $container->addCompilerPass(new ResolversCompilerPass);
/** @var $extension LiipImagineExtension */
$extension = $container->getExtension('liip_imagine');
View
114 Tests/DependencyInjection/ConfigurationTest.php
@@ -28,7 +28,15 @@ public function testCouldBeConstructedWithResolversAndLoadersFactoriesAsArgument
public function testInjectLoaderFactoryConfig()
{
$config = $this->processConfiguration(
- new Configuration(array(), array(new FooLoaderFactory, new FileSystemLoaderFactory)),
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ),
+ array(
+ new FooLoaderFactory,
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'loaders' => array(
'aLoader' => array(
@@ -51,7 +59,15 @@ public function testInjectLoaderFactoryConfig()
public function testAllowToUseLoaderFactorySeveralTimes()
{
$config = $this->processConfiguration(
- new Configuration(array(), array(new FooLoaderFactory, new FileSystemLoaderFactory)),
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ),
+ array(
+ new FooLoaderFactory,
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'loaders' => array(
'aLoader' => array(
@@ -77,7 +93,14 @@ public function testAllowToUseLoaderFactorySeveralTimes()
public function testSetFilesystemLoaderAsDefaultLoaderIfNotDefined()
{
$config = $this->processConfiguration(
- new Configuration(array(), array(new FileSystemLoaderFactory)),
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ),
+ array(
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'loaders' => array(
)
@@ -89,10 +112,56 @@ public function testSetFilesystemLoaderAsDefaultLoaderIfNotDefined()
$this->assertArrayHasKey('filesystem', $config['loaders']['default']);
}
+ public function testSetFilesystemLoaderAsDefaultIfLoadersSectionNotDefined()
+ {
+ $config = $this->processConfiguration(
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ),
+ array(
+ new FileSystemLoaderFactory
+ )
+ ),
+ array(array())
+ );
+
+ $this->assertArrayHasKey('loaders', $config);
+ $this->assertArrayHasKey('default', $config['loaders']);
+ $this->assertArrayHasKey('filesystem', $config['loaders']['default']);
+ }
+
+ public function testSetWebPathResolversAsDefaultIfResolversSectionNotDefined()
+ {
+ $config = $this->processConfiguration(
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ),
+ array(
+ new FileSystemLoaderFactory
+ )
+ ),
+ array(array())
+ );
+
+ $this->assertArrayHasKey('resolvers', $config);
+ $this->assertArrayHasKey('default', $config['resolvers']);
+ $this->assertArrayHasKey('web_path', $config['resolvers']['default']);
+ }
+
public function testShouldNotOverwriteDefaultLoaderIfDefined()
{
$config = $this->processConfiguration(
- new Configuration(array(), array(new FooLoaderFactory, new FileSystemLoaderFactory)),
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ),
+ array(
+ new FooLoaderFactory,
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'loaders' => array(
'default' => array(
@@ -113,7 +182,14 @@ public function testShouldNotOverwriteDefaultLoaderIfDefined()
public function testInjectResolverFactoryConfig()
{
$config = $this->processConfiguration(
- new Configuration(array(new BarResolverFactory, new WebPathResolverFactory), array()),
+ new Configuration(
+ array(
+ new BarResolverFactory,
+ new WebPathResolverFactory
+ ), array(
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'resolvers' => array(
'aResolver' => array(
@@ -136,7 +212,15 @@ public function testInjectResolverFactoryConfig()
public function testAllowToUseResolverFactorySeveralTimes()
{
$config = $this->processConfiguration(
- new Configuration(array(new BarResolverFactory, new WebPathResolverFactory), array()),
+ new Configuration(
+ array(
+ new BarResolverFactory,
+ new WebPathResolverFactory
+ ),
+ array(
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'resolvers' => array(
'aResolver' => array(
@@ -162,7 +246,13 @@ public function testAllowToUseResolverFactorySeveralTimes()
public function testSetWebPathAsDefaultResolverIfNotDefined()
{
$config = $this->processConfiguration(
- new Configuration(array(new WebPathResolverFactory), array()),
+ new Configuration(
+ array(
+ new WebPathResolverFactory
+ ), array(
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'resolvers' => array(
)
@@ -177,7 +267,15 @@ public function testSetWebPathAsDefaultResolverIfNotDefined()
public function testShouldNotOverwriteDefaultResolverIfDefined()
{
$config = $this->processConfiguration(
- new Configuration(array(new BarResolverFactory, new WebPathResolverFactory), array()),
+ new Configuration(
+ array(
+ new BarResolverFactory,
+ new WebPathResolverFactory
+ ),
+ array(
+ new FileSystemLoaderFactory
+ )
+ ),
array(array(
'resolvers' => array(
'default' => array(
View
6 Tests/DependencyInjection/LiipImagineExtensionTest.php
@@ -2,6 +2,8 @@
namespace Liip\ImagineBundle\Tests\DependencyInjection;
+use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory;
+use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory;
use Liip\ImagineBundle\Tests\AbstractTest;
use Liip\ImagineBundle\DependencyInjection\LiipImagineExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -65,6 +67,8 @@ protected function createEmptyConfiguration()
{
$this->containerBuilder = new ContainerBuilder();
$loader = new LiipImagineExtension();
+ $loader->addLoaderFactory(new FileSystemLoaderFactory);
+ $loader->addResolverFactory(new WebPathResolverFactory);
$loader->load(array(array()), $this->containerBuilder);
$this->assertTrue($this->containerBuilder instanceof ContainerBuilder);
}
@@ -76,6 +80,8 @@ protected function createFullConfiguration()
{
$this->containerBuilder = new ContainerBuilder();
$loader = new LiipImagineExtension();
+ $loader->addLoaderFactory(new FileSystemLoaderFactory);
+ $loader->addResolverFactory(new WebPathResolverFactory);
$loader->load(array($this->getFullConfig()), $this->containerBuilder);
$this->assertTrue($this->containerBuilder instanceof ContainerBuilder);
}
View
4 Tests/Imagine/Cache/CacheManagerTest.php
@@ -45,7 +45,7 @@ public function testGetBrowserPathWithoutResolver()
$cacheManager = new CacheManager($config, $this->createRouterMock(), new UriSigner('secret'));
- $this->setExpectedException('OutOfBoundsException', 'Could not find resolver for "thumbnail" filter type');
+ $this->setExpectedException('OutOfBoundsException', 'Could not find resolver "default" for "thumbnail" filter type');
$cacheManager->getBrowserPath('cats.jpeg', 'thumbnail');
}
@@ -147,7 +147,7 @@ public function testThrowsIfConcreteResolverNotExists()
{
$cacheManager = new CacheManager($this->createFilterConfigurationMock(), $this->createRouterMock(), new UriSigner('secret'));
- $this->setExpectedException('OutOfBoundsException', 'Could not find resolver for "thumbnail" filter type');
+ $this->setExpectedException('OutOfBoundsException', 'Could not find resolver "default" for "thumbnail" filter type');
$this->assertFalse($cacheManager->resolve('cats.jpeg', 'thumbnail'));
}
View
2  Tests/Imagine/Data/DataManagerTest.php
@@ -239,7 +239,7 @@ public function testThrowIfLoaderNotRegisteredForGivenFilterOnFind()
$dataManager = new DataManager($this->getMockMimeTypeGuesser(), $this->getMockExtensionGuesser(), $config);
- $this->setExpectedException('InvalidArgumentException', 'Could not find data loader for "thumbnail" filter type');
+ $this->setExpectedException('InvalidArgumentException', 'Could not find data loader "" for "thumbnail" filter type');
$dataManager->find('thumbnail', 'cats.jpeg');
}
View
42 Tests/LiipImagineBundleTest.php
@@ -29,7 +29,7 @@ public function testAddLoadersCompilerPassOnBuild()
->will($this->returnValue($this->createExtensionMock()))
;
$containerMock
- ->expects($this->once())
+ ->expects($this->at(0))
->method('addCompilerPass')
->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass'))
;
@@ -39,6 +39,46 @@ public function testAddLoadersCompilerPassOnBuild()
$bundle->build($containerMock);
}
+ public function testAddFiltersCompilerPassOnBuild()
+ {
+ $containerMock = $this->createContainerBuilderMock();
+ $containerMock
+ ->expects($this->atLeastOnce())
+ ->method('getExtension')
+ ->with('liip_imagine')
+ ->will($this->returnValue($this->createExtensionMock()))
+ ;
+ $containerMock
+ ->expects($this->at(1))
+ ->method('addCompilerPass')
+ ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass'))
+ ;
+
+ $bundle = new LiipImagineBundle;
+
+ $bundle->build($containerMock);
+ }
+
+ public function testAddResolversCompilerPassOnBuild()
+ {
+ $containerMock = $this->createContainerBuilderMock();
+ $containerMock
+ ->expects($this->atLeastOnce())
+ ->method('getExtension')
+ ->with('liip_imagine')
+ ->will($this->returnValue($this->createExtensionMock()))
+ ;
+ $containerMock
+ ->expects($this->at(2))
+ ->method('addCompilerPass')
+ ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\ResolversCompilerPass'))
+ ;
+
+ $bundle = new LiipImagineBundle;
+
+ $bundle->build($containerMock);
+ }
+
public function testAddWebPathResolverFactoryOnBuild()
{
$extensionMock = $this->createExtensionMock();
Please sign in to comment.
Something went wrong with that request. Please try again.