Skip to content

Commit

Permalink
ability to redefine key generator as service
Browse files Browse the repository at this point in the history
  • Loading branch information
mente committed Mar 24, 2016
1 parent 956f497 commit a20993b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
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
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 a20993b

Please sign in to comment.