Skip to content

Commit 6684048

Browse files
committed
Merge pull request #104 from FriendsOfSymfony/configuration-test-xml
Configuration test xml
2 parents 05906e0 + 13b768c commit 6684048

15 files changed

+240
-18
lines changed

DependencyInjection/Configuration.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,19 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode)
128128
// todo validate there is some header defined
129129
->children()
130130
->arrayNode('cache_control')
131-
->useAttributeAsKey('name')
132-
->prototype('scalar')->end()
133131
->info('Add the specified cache control directives.')
132+
->children()
133+
->scalarNode('max_age')->end()
134+
->scalarNode('s_maxage')->end()
135+
->booleanNode('private')->end()
136+
->booleanNode('public')->end()
137+
->booleanNode('must_revalidate')->end()
138+
->booleanNode('proxy_revalidate')->end()
139+
->booleanNode('no_transform')->end()
140+
->booleanNode('no_cache')->end()
141+
->scalarNode('stale_if_error')->end()
142+
->scalarNode('stale_while_revalidate')->end()
143+
->end()
134144
->end()
135145
->scalarNode('last_modified')
136146
->validate()
@@ -351,8 +361,8 @@ private function addInvalidationSection(ArrayNodeDefinition $rootNode)
351361
->end()
352362
->arrayNode('rules')
353363
->info('Set what requests should invalidate which target routes.')
354-
->fixXmlConfig('route')
355364
->prototype('array')
365+
->fixXmlConfig('route')
356366
->children();
357367

358368
$this->addMatch($rules);
@@ -378,12 +388,12 @@ private function addInvalidationSection(ArrayNodeDefinition $rootNode)
378388
private function addUserContextListenerSection(ArrayNodeDefinition $rootNode)
379389
{
380390
$rootNode
381-
->fixXmlConfig('user_identifier_header')
382391
->children()
383392
->arrayNode('user_context')
384393
->info('Listener that returns the request for the user context hash as early as possible.')
385394
->addDefaultsIfNotSet()
386395
->canBeEnabled()
396+
->fixXmlConfig('user_identifier_header')
387397
->children()
388398
->arrayNode('match')
389399
->addDefaultsIfNotSet()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<cache-manager enabled="true" />
6+
</config>
7+
8+
</container>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache" />
5+
6+
</container>

Tests/Resources/Fixtures/config/full.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@
1414
),
1515
'headers' => array(
1616
'cache_control' => array(
17+
'max_age' => 1,
18+
's_maxage' => 2,
1719
'public' => true,
20+
'must_revalidate' => true,
21+
'proxy_revalidate' => false,
22+
'no_transform' => true,
23+
'no_cache' => false,
24+
'stale_if_error' => 3,
25+
'stale_while_revalidate' => 4,
1826
),
1927
'last_modified' => '-1 hour',
2028
'reverse_proxy_ttl' => 42,
21-
'vary' => 'Cookie',
29+
'vary' => 'Cookie,Authorization',
2230
),
2331
),
2432
),
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<cache-control>
6+
<rule>
7+
<match
8+
path="/abc"
9+
host="fos"
10+
>
11+
<method>GET</method>
12+
<method>POST</method>
13+
<ip>1.2.3.4</ip>
14+
<ip>1.1.1.1</ip>
15+
<attribute name="_controller">fos.user_bundle.*</attribute>
16+
<additional-cacheable-status>100</additional-cacheable-status>
17+
<additional-cacheable-status>500</additional-cacheable-status>
18+
</match>
19+
<headers last-modified="-1 hour" reverse-proxy-ttl="42">
20+
<cache-control
21+
max-age="1"
22+
s-maxage="2"
23+
public="true"
24+
must-revalidate="true"
25+
proxy-revalidate="false"
26+
no-transform="true"
27+
no-cache="false"
28+
stale-if-error="3"
29+
stale-while-revalidate="4"
30+
/>
31+
<vary>Cookie</vary>
32+
<vary>Authorization</vary>
33+
</headers>
34+
</rule>
35+
</cache-control>
36+
<proxy-client>
37+
<varnish base-url="/test">
38+
<server>22.22.22.22</server>
39+
</varnish>
40+
</proxy-client>
41+
42+
<cache-manager enabled="true"/>
43+
44+
<tags>
45+
<rule>
46+
<match path="/def" host="friends">
47+
<method>PUT</method>
48+
<method>DELETE</method>
49+
<ip>99.99.99.99</ip>
50+
<attribute name="_foo">bar</attribute>
51+
<additional-cacheable-status>501</additional-cacheable-status>
52+
<additional-cacheable-status>502</additional-cacheable-status>
53+
</match>
54+
<tag>a</tag>
55+
<tag>b</tag>
56+
<tag-expression>"a"</tag-expression>
57+
<tag-expression>"b"</tag-expression>
58+
</rule>
59+
</tags>
60+
61+
<invalidation>
62+
<rule>
63+
<match path="/hij" host="symfony">
64+
<method>PATCH</method>
65+
<ip>42.42.42.42</ip>
66+
<attribute name="_format">json</attribute>
67+
<additional-cacheable-status>404</additional-cacheable-status>
68+
<additional-cacheable-status>403</additional-cacheable-status>
69+
</match>
70+
<route name="invalidate_route1" ignore-extra-params="false"/>
71+
</rule>
72+
</invalidation>
73+
74+
<user-context hash-cache-ttl="300" role-provider="true" user-hash-header="FOS-User-Context-Hash">
75+
<match method="GET"/>
76+
<user-identifier-header>Cookie</user-identifier-header>
77+
<user-identifier-header>Authorization</user-identifier-header>
78+
</user-context>
79+
80+
<flash-message name="flashtest" path="/x" host="y" secure="true" httpOnly="false"/>
81+
82+
<debug header="FOS-Cache-Debug"/>
83+
84+
</config>
85+
</container>

Tests/Resources/Fixtures/config/full.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ fos_http_cache:
1919
- 500
2020
headers:
2121
cache_control:
22+
max_age: 1
23+
s_maxage: 2
2224
public: true
25+
must_revalidate: true
26+
proxy_revalidate: false
27+
no_transform: true
28+
no_cache: false
29+
stale_if_error: 3
30+
stale_while_revalidate: 4
2331
last_modified: -1 hour
2432
reverse_proxy_ttl: 42
25-
vary: Cookie
33+
vary:
34+
- Cookie
35+
- Authorization
2636
proxy_client:
2737
varnish:
2838
servers: 22.22.22.22
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<cache-control>
6+
<rule>
7+
<match path="/abc"/>
8+
<headers last-modified="this is not a valid date"/>
9+
</rule>
10+
</cache-control>
11+
12+
</config>
13+
</container>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<cache-manager enabled="false" />
6+
<invalidation enabled="true" />
7+
</config>
8+
9+
</container>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<invalidation enabled="false">
6+
<rule>
7+
<match path="/def"/>
8+
<route name="routename"/>
9+
</rule>
10+
</invalidation>
11+
</config>
12+
13+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<proxy-client>
6+
<nginx base-url="/test" purge-location="/purge">
7+
<server>22.22.22.22</server>
8+
</nginx>
9+
</proxy-client>
10+
11+
</config>
12+
</container>

0 commit comments

Comments
 (0)