Skip to content

Commit

Permalink
Add tags.strict config param
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Feb 5, 2017
1 parent d0b4fc3 commit c441e80
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Resources/doc/reference/configuration/tags.rst
Expand Up @@ -41,6 +41,20 @@ section of the tag configuration and ``@tag`` :ref:`annotations<tag>`.
tags:
expression_language: app.expression_language
``strict``
----------

**type**: ``boolean`` **default**: ``false``

Set this to ``true`` to throw an exception when an empty or null tag is added.

.. code-block:: yaml
# app/config/config.yml
fos_http_cache:
tags:
strict: true
``rules``
---------

Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -449,6 +449,7 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
->defaultValue('auto')
->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.')
->end()
->booleanNode('strict')->defaultFalse()->end()
->scalarNode('expression_language')
->defaultNull()
->info('Service name of a custom ExpressionLanugage to use.')
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/FOSHttpCacheExtension.php
Expand Up @@ -339,6 +339,7 @@ private function loadCacheTagging(ContainerBuilder $container, XmlFileLoader $lo

$container->setParameter($this->getAlias().'.compiler_pass.tag_annotations', true);
$container->setParameter($this->getAlias().'.tag_handler.header', $config['header']);
$container->setParameter($this->getAlias().'.tag_handler.strict', $config['strict']);
$loader->load('cache_tagging.xml');

if (!empty($config['expression_language'])) {
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/cache_tagging.xml
Expand Up @@ -7,6 +7,9 @@
<services>
<service id="fos_http_cache.http.symfony_response_tagger" class="FOS\HttpCacheBundle\Http\SymfonyResponseTagger">
<argument type="service" id="fos_http_cache.default_proxy_client"/>
<argument type="collection">
<argument key="strict">%fos_http_cache.tag_handler.strict%</argument>
</argument>
</service>

<service id="fos_http_cache.twig.tag_extension" class="FOS\HttpCacheBundle\Twig\CacheTagExtension">
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/Fixtures/app/config/config.yml
Expand Up @@ -35,6 +35,7 @@ fos_http_cache:
path: ^/cached
tags: [area]
tag_expressions: ["'area-'~id"]
strict: true
user_context:
user_identifier_headers:
- Cookie
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Expand Up @@ -101,6 +101,7 @@ public function testSupportsAllConfigFormats()
],
'tags' => [
'enabled' => 'auto',
'strict' => false,
'header' => 'FOS-Tags',
'expression_language' => 'acme.expression_language',
'rules' => [
Expand Down Expand Up @@ -198,6 +199,7 @@ public function testCustomProxyClient()
'generate_url_type' => 'auto',
];
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['tags']['strict'] = false;
$expectedConfiguration['invalidation']['enabled'] = 'auto';

$formats = array_map(function ($path) {
Expand Down Expand Up @@ -229,6 +231,7 @@ public function testSupportsNginx()
$expectedConfiguration['cache_manager']['enabled'] = 'auto';
$expectedConfiguration['cache_manager']['generate_url_type'] = 'auto';
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['tags']['strict'] = false;
$expectedConfiguration['invalidation']['enabled'] = 'auto';
$expectedConfiguration['user_context']['logout_handler']['enabled'] = 'auto';

Expand Down Expand Up @@ -260,6 +263,7 @@ public function testSupportsSymfony()
$expectedConfiguration['cache_manager']['enabled'] = 'auto';
$expectedConfiguration['cache_manager']['generate_url_type'] = 'auto';
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['tags']['strict'] = false;
$expectedConfiguration['invalidation']['enabled'] = 'auto';
$expectedConfiguration['user_context']['logout_handler']['enabled'] = 'auto';

Expand All @@ -285,6 +289,7 @@ public function testSupportsNoop()
$expectedConfiguration['cache_manager']['enabled'] = 'auto';
$expectedConfiguration['cache_manager']['generate_url_type'] = 'auto';
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['tags']['strict'] = false;
$expectedConfiguration['invalidation']['enabled'] = 'auto';
$expectedConfiguration['user_context']['logout_handler']['enabled'] = 'auto';

Expand Down Expand Up @@ -348,6 +353,7 @@ public function testSplitOptions()
$expectedConfiguration['cache_manager']['enabled'] = 'auto';
$expectedConfiguration['cache_manager']['generate_url_type'] = 'auto';
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['tags']['strict'] = false;
$expectedConfiguration['invalidation']['enabled'] = 'auto';
$expectedConfiguration['user_context']['logout_handler']['enabled'] = 'auto';

Expand Down Expand Up @@ -479,6 +485,7 @@ private function getEmptyConfig()
],
'tags' => [
'enabled' => false,
'strict' => false,
'header' => 'X-Cache-Tags',
'expression_language' => null,
'rules' => [],
Expand Down

0 comments on commit c441e80

Please sign in to comment.