Skip to content

Commit

Permalink
Merge pull request #109 from FriendsOfSymfony/tags-header-config
Browse files Browse the repository at this point in the history
Make tags header configurable
  • Loading branch information
ddeboer committed Jul 30, 2014
2 parents 4f4bcea + 68a9985 commit d22a5e3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
->defaultValue('auto')
->info('Allows to disable the listener for tag annotations when your project does not use the annotations. Enabled by default if you have expression language and the cache manager.')
->end()
->scalarNode('header')
->defaultValue('X-Cache-Tags')
->info('HTTP header that contains cache tags')
->end()
->arrayNode('rules')
->prototype('array')
->fixXmlConfig('tag')
Expand Down
6 changes: 5 additions & 1 deletion DependencyInjection/FOSHttpCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -74,6 +73,11 @@ public function load(array $configs, ContainerBuilder $container)
// silently skip if set to auto
throw new InvalidConfigurationException('The TagSubscriber requires symfony/expression-language and needs the cache_manager to be configured');
}

$tagsHeader = $config['tags']['header'];
$container->getDefinition($this->getAlias().'.cache_manager')
->addMethodCall('setTagsHeader', array($tagsHeader))
;
}

if ($config['invalidation']['enabled']) {
Expand Down
1 change: 1 addition & 0 deletions Tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'enabled' => true,
),
'tags' => array(
'header' => 'FOS-Tags',
'rules' => array(
array(
'match' => array(
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<cache-manager enabled="true"/>

<tags>
<tags header="FOS-Tags">
<rule>
<match path="/def" host="friends">
<method>PUT</method>
Expand Down
1 change: 1 addition & 0 deletions Tests/Resources/Fixtures/config/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fos_http_cache:
enabled: true

tags:
header: FOS-Tags
rules:
-
match:
Expand Down
2 changes: 2 additions & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function testSupportsAllConfigFormats()
),
'tags' => array(
'enabled' => 'auto',
'header' => 'FOS-Tags',
'rules' => array(
array(
'match' => array(
Expand Down Expand Up @@ -410,6 +411,7 @@ private function getEmptyConfig()
),
'tags' => array(
'enabled' => false,
'header' => 'X-Cache-Tags',
'rules' => array(),
),
'invalidation' => array(
Expand Down

0 comments on commit d22a5e3

Please sign in to comment.