Skip to content

Commit

Permalink
Merge pull request #11 from mente/opt-key-generator
Browse files Browse the repository at this point in the history
ability to redefine key generator as service
  • Loading branch information
EmanueleMinotto committed Apr 5, 2016
2 parents 956f497 + dd7ddd7 commit 37aa9e1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function getConfigTreeBuilder()
->cannotBeEmpty()
->defaultValue('twig_cache.strategy')
->end()
->scalarNode('key_generator')
->cannotBeEmpty()
->defaultValue('twig_cache.strategy.spl_object_hash_key_generator')
->info('service id that implements KeyGeneratorInterface to generate a key for template cache')
->end()
->end();

return $treeBuilder;
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/TwigCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function load(array $config, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $config);

$container->setAlias('twig_cache.service', $config['service']);
$container->setAlias('twig_cache.strategy.key_generator', $config['key_generator']);

$loader = new Loader\XmlFileLoader(
$container,
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</service>
<service class="%twig_cache.strategy.generational.class%" id="twig_cache.strategy.generational">
<argument id="twig_cache.adapter" type="service"/>
<argument id="twig_cache.strategy.spl_object_hash_key_generator" type="service"/>
<argument id="twig_cache.strategy.key_generator" type="service"/>
</service>
<service class="%twig_cache.strategy.lifetime.class%" id="twig_cache.strategy.lifetime">
<argument id="twig_cache.adapter" type="service"/>
Expand Down
3 changes: 2 additions & 1 deletion Resources/doc/configuration-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Default Bundle Configuration
twig_cache:
profiler: '%kernel.debug%'
service: # required
strategy: twig_cache.strategy
strategy: twig_cache.strategy
key_generator: twig_cache.strategy.spl_object_hash_key_generator
1 change: 1 addition & 0 deletions Tests/DependencyInjection/TwigCacheExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testService()
{
$this->assertContainerBuilderHasService('twig_cache.extension');
$this->assertContainerBuilderHasService('twig_cache.service');
$this->assertContainerBuilderHasService('twig_cache.strategy.key_generator');
}

/**
Expand Down

0 comments on commit 37aa9e1

Please sign in to comment.