Skip to content

Commit

Permalink
Merge pull request #101 from Spea/master
Browse files Browse the repository at this point in the history
Added option to disable cache_clearer
  • Loading branch information
lsmith77 committed Aug 23, 2012
2 parents e01cb51 + c4a6ccb commit f67aaa4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '/') : '';
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -454,7 +460,7 @@ liip_imagine:
my_custom_filter: { }
```

Add loader to your services
Add loader to your services
``` xml
<service id="liip_imagine.data.loader.grid_fs" class="Liip\ImagineBundle\Imagine\Data\Loader\GridFSLoader">
<tag name="liip_imagine.data.loader" loader="grid_fs" />
Expand Down
19 changes: 19 additions & 0 deletions Resources/config/cache_clearer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="liip_imagine.cache.clearer.class">Liip\ImagineBundle\Imagine\Cache\CacheClearer</parameter>
</parameters>

<services>

<service id="liip_imagine.cache.clearer" class="%liip_imagine.cache.clearer.class%">
<tag name="kernel.cache_clearer" />
<argument type="service" id="liip_imagine.cache.manager" />
<argument>%liip_imagine.cache_prefix%</argument>
</service>

</services>
</container>
12 changes: 0 additions & 12 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<parameter key="liip_imagine.cache.resolver.web_path.class">Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver</parameter>
<parameter key="liip_imagine.cache.resolver.no_cache.class">Liip\ImagineBundle\Imagine\Cache\Resolver\NoCacheResolver</parameter>

<!-- Cache clearers' classes -->

<parameter key="liip_imagine.cache.clearer.class">Liip\ImagineBundle\Imagine\Cache\CacheClearer</parameter>

</parameters>

<services>
Expand Down Expand Up @@ -159,13 +155,5 @@
<argument type="service" id="filesystem" />
</service>

<!-- Cache Clearer -->

<service id="liip_imagine.cache.clearer" class="%liip_imagine.cache.clearer.class%">
<tag name="kernel.cache_clearer" />
<argument type="service" id="liip_imagine.cache.manager" />
<argument>%liip_imagine.cache_prefix%</argument>
</service>

</services>
</container>
10 changes: 9 additions & 1 deletion Tests/DependencyInjection/LiipImagineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -63,6 +63,13 @@ public function testCacheClearerRegistration()
}
}

public function testCacheClearerIsNotRegistered()
{
$this->createFullConfiguration();

$this->assertFalse($this->containerBuilder->hasDefinition('liip_imagine.cache.clearer'));
}

/**
* @return ContainerBuilder
*/
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f67aaa4

Please sign in to comment.