diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 13147cf88..75e605796 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -32,6 +32,7 @@ public function getConfigTreeBuilder()
->scalarNode('cache_prefix')->defaultValue('/media/cache')->end()
->scalarNode('cache')->defaultValue('web_path')->end()
->scalarNode('cache_base_path')->defaultValue('')->end()
+ ->booleanNode('auto_clear_cache')->defaultValue(true)->end()
->scalarNode('data_loader')->defaultValue('filesystem')->end()
->scalarNode('controller_action')->defaultValue('liip_imagine.controller:filterAction')->end()
->arrayNode('formats')
diff --git a/DependencyInjection/LiipImagineExtension.php b/DependencyInjection/LiipImagineExtension.php
index cb5ce1729..5f1bd9021 100644
--- a/DependencyInjection/LiipImagineExtension.php
+++ b/DependencyInjection/LiipImagineExtension.php
@@ -25,6 +25,10 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('imagine.xml');
+ if ($config['auto_clear_cache']) {
+ $loader->load('cache_clearer.xml');
+ }
+
$container->setAlias('liip_imagine', new Alias('liip_imagine.'.$config['driver']));
$cachePrefix = $config['cache_prefix'] ? '/'.trim($config['cache_prefix'], '/') : '';
diff --git a/README.md b/README.md
index 7b8828824..a6e875597 100644
--- a/README.md
+++ b/README.md
@@ -169,6 +169,7 @@ liip_imagine:
data_root: %liip_imagine.web_root%
cache_prefix: /media/cache
cache: web_path
+ auto_clear_cache true
data_loader: filesystem
controller_action: liip_imagine.controller:filterAction
formats: []
@@ -212,6 +213,11 @@ There are several configuration options available:
default: web_path (which means the standard web_path resolver is used)
+ - `auto_clear_cache` - Whether or not to clear the image cache when the `kernel.cache_clearer` event occurs.
+ This option doesn't have any effect in symfony < 2.1
+
+ default: true
+
- `data_loader` - name of a custom data loader
default: filesystem (which means the standard filesystem loader is used)
@@ -454,7 +460,7 @@ liip_imagine:
my_custom_filter: { }
```
-Add loader to your services
+Add loader to your services
``` xml
diff --git a/Resources/config/cache_clearer.xml b/Resources/config/cache_clearer.xml
new file mode 100644
index 000000000..ad956c8d8
--- /dev/null
+++ b/Resources/config/cache_clearer.xml
@@ -0,0 +1,19 @@
+
+
+
+
+ Liip\ImagineBundle\Imagine\Cache\CacheClearer
+
+
+
+
+
+
+
+ %liip_imagine.cache_prefix%
+
+
+
+
diff --git a/Resources/config/imagine.xml b/Resources/config/imagine.xml
index 481c19e73..0f8f9ad2e 100644
--- a/Resources/config/imagine.xml
+++ b/Resources/config/imagine.xml
@@ -48,10 +48,6 @@
Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver
Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheResolver
-
-
- Liip\ImagineBundle\Imagine\Cache\CacheClearer
-
@@ -159,13 +155,5 @@
-
-
-
-
-
- %liip_imagine.cache_prefix%
-
-
diff --git a/Tests/DependencyInjection/LiipImagineExtensionTest.php b/Tests/DependencyInjection/LiipImagineExtensionTest.php
index f2c828ee5..adf1d4a79 100644
--- a/Tests/DependencyInjection/LiipImagineExtensionTest.php
+++ b/Tests/DependencyInjection/LiipImagineExtensionTest.php
@@ -50,7 +50,7 @@ public function testLoadWithDefaults()
public function testCacheClearerRegistration()
{
- $this->createFullConfiguration();
+ $this->createEmptyConfiguration();
if ('2' == Kernel::MAJOR_VERSION && '0' == Kernel::MINOR_VERSION) {
$this->assertFalse($this->containerBuilder->hasDefinition('liip_imagine.cache.clearer'));
@@ -63,6 +63,13 @@ public function testCacheClearerRegistration()
}
}
+ public function testCacheClearerIsNotRegistered()
+ {
+ $this->createFullConfiguration();
+
+ $this->assertFalse($this->containerBuilder->hasDefinition('liip_imagine.cache.clearer'));
+ }
+
/**
* @return ContainerBuilder
*/
@@ -92,6 +99,7 @@ protected function getFullConfig()
web_root: ../foo/bar
cache_prefix: /imagine/cache
cache: false
+auto_clear_cache: false
formats: ['json', 'xml', 'jpg', 'png', 'gif']
filter_sets:
small: