Skip to content

Commit 9bbf553

Browse files
committed
make tag annotations optional inside tags to allow using them without Sensio FrameworkExtraBundle
1 parent d44e264 commit 9bbf553

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
2.6.1
5+
-----
6+
7+
### Fixed
8+
9+
* Cache Tagging: It is now possible to use cache tagging without installing the
10+
Sensio ``FrameworkExtraBundle``. There is a new configuration option
11+
``tags.annotations.enabled`` that can be set to ``false``.
12+
413
2.6.0
514
-----
615

src/DependencyInjection/Compiler/TagListenerPass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public function process(ContainerBuilder $container)
2929
&& !$this->hasControllerListener($container)
3030
) {
3131
throw new \RuntimeException(
32-
'Tag support requires SensioFrameworkExtraBundle’s ControllerListener for the annotations. '
33-
.'Please install sensio/framework-extra-bundle and add it to your AppKernel.'
32+
'Tag annotations are enabled by default because otherwise things could silently not work.'
33+
.' The annotations require the SensioFrameworkExtraBundle ControllerListener. If you do not use'
34+
.' annotations for tags, set "fos_http_cache.tags.annotations.enabled: false". Otherwise install'
35+
.' sensio/framework-extra-bundle and enabled it in your kernel.'
3436
);
3537
}
3638
}

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,11 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
645645
->enumNode('enabled')
646646
->values([true, false, 'auto'])
647647
->defaultValue('auto')
648-
->info('Allows to disable the event subscriber for tag configuration and annotations when your project does not use the annotations. Enabled by default if you configured the cache manager.')
648+
->info('Allows to disable tag support. Enabled by default if you configured the cache manager and have a proxy client that supports tagging.')
649+
->end()
650+
->arrayNode('annotations')
651+
->info('Annotations require the FrameworkExtraBundle. Because we can not detect whether annotations are used when the FrameworkExtraBundle is not available, this option must be set to false explicitly if the application does not use annotations.')
652+
->canBeDisabled()
649653
->end()
650654
->booleanNode('strict')->defaultFalse()->end()
651655
->scalarNode('expression_language')

src/DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private function loadCacheTagging(ContainerBuilder $container, XmlFileLoader $lo
469469
throw new InvalidConfigurationException(sprintf('You can not enable cache tagging with the %s client', $client));
470470
}
471471

472-
$container->setParameter('fos_http_cache.compiler_pass.tag_annotations', true);
472+
$container->setParameter('fos_http_cache.compiler_pass.tag_annotations', $config['annotations']['enabled']);
473473
$container->setParameter('fos_http_cache.tag_handler.response_header', $config['response_header']);
474474
$container->setParameter('fos_http_cache.tag_handler.separator', $config['separator']);
475475
$container->setParameter('fos_http_cache.tag_handler.strict', $config['strict']);

tests/Unit/DependencyInjection/Compiler/TagListenerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TagListenerPassTest extends TestCase
2424

2525
/**
2626
* @expectedException \RuntimeException
27-
* @expectedExceptionMessage requires SensioFrameworkExtraBundle
27+
* @expectedExceptionMessage require the SensioFrameworkExtraBundle
2828
*/
2929
public function testNoFrameworkBundle()
3030
{

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public function testSupportsAllConfigFormats()
112112
],
113113
'tags' => [
114114
'enabled' => 'auto',
115+
'annotations' => [
116+
'enabled' => true,
117+
],
115118
'strict' => false,
116119
'response_header' => 'FOS-Tags',
117120
'expression_language' => 'acme.expression_language',
@@ -685,6 +688,9 @@ private function getEmptyConfig()
685688
],
686689
'tags' => [
687690
'enabled' => false,
691+
'annotations' => [
692+
'enabled' => true,
693+
],
688694
'strict' => false,
689695
'response_header' => 'X-Cache-Tags',
690696
'expression_language' => null,

tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ public function testConfigLoadTagRules()
246246
$this->assertRequestMatcherCreated($container, ['_controller' => '^AcmeBundle:Default:index$']);
247247
$this->assertListenerHasRule($container, 'fos_http_cache.event_listener.tag');
248248
$this->assertFalse($container->hasDefinition('fos_http_cache.tag_handler.max_header_value_length_header_formatter'));
249+
$this->assertTrue($container->hasParameter('fos_http_cache.compiler_pass.tag_annotations'));
250+
$this->assertTrue($container->getParameter('fos_http_cache.compiler_pass.tag_annotations'));
251+
}
252+
253+
public function testConfigLoadTagDisableAnnotations()
254+
{
255+
$config = $this->getBaseConfig() + [
256+
'tags' => [
257+
'annotations' => false,
258+
],
259+
];
260+
261+
$container = $this->createContainer();
262+
$this->extension->load([$config], $container);
263+
264+
$this->assertTrue($container->hasParameter('fos_http_cache.compiler_pass.tag_annotations'));
265+
$this->assertFalse($container->getParameter('fos_http_cache.compiler_pass.tag_annotations'));
249266
}
250267

251268
public function testConfigWithMaxHeaderLengthValueDecoratesTagService()

0 commit comments

Comments
 (0)