Skip to content

Commit ada9883

Browse files
alcoholdbu
authored andcommitted
add support for the new respect_response_cache_directives configuration
1 parent 1b3bec5 commit ada9883

File tree

9 files changed

+95
-9
lines changed

9 files changed

+95
-9
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@
55
### Added
66

77
- The real request method and target url are now displayed in the profiler.
8+
- Support the cache plugin configuration for `respect_response_cache_directives`.
89

910
### Changed
1011

1112
- The profiler design has been updated.
1213

14+
### Deprecated
15+
16+
- The configuration option `cache.config.respect_cache_headers` should no longer be used. Use `...respect_response_cache_directives` instead.
17+
18+
## 1.4.1 - 2017-02-23
19+
20+
### Fixed
21+
22+
- Make sure we always have a stack
23+
1324
## 1.4.0 - 2017-02-21
1425

1526
### Changed

DependencyInjection/Configuration.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
88
use Symfony\Component\Config\Definition\ConfigurationInterface;
99
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
10+
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
1011

1112
/**
1213
* This class contains the configuration information for the bundle.
@@ -368,9 +369,35 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
368369
->end()
369370
->arrayNode('config')
370371
->addDefaultsIfNotSet()
372+
->validate()
373+
->ifTrue(function ($config) {
374+
// Cannot set both respect_cache_headers and respect_response_cache_directives
375+
return isset($config['respect_cache_headers'], $config['respect_response_cache_directives']);
376+
})
377+
->thenInvalid('You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaniously. Use "respect_response_cache_directives" instead.')
378+
->end()
371379
->children()
372380
->scalarNode('default_ttl')->defaultValue(0)->end()
373-
->scalarNode('respect_cache_headers')->defaultNull()->end()
381+
->enumNode('respect_cache_headers')
382+
->values([null, true, false])
383+
->beforeNormalization()
384+
->always(function ($v) {
385+
@trigger_error('The option "respect_cache_headers" is deprecated since version 1.3 and will be removed in 2.0. Use "respect_response_cache_directives" instead.', E_USER_DEPRECATED);
386+
387+
return $v;
388+
})
389+
->end()
390+
->end()
391+
->variableNode('respect_response_cache_directives')
392+
->validate()
393+
->always(function ($v) {
394+
if (is_null($v) || is_array($v)) {
395+
return $v;
396+
}
397+
throw new InvalidTypeException();
398+
})
399+
->end()
400+
->end()
374401
->end()
375402
->end()
376403
->end()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
httplug:
2+
plugins:
3+
cache:
4+
cache_pool: my_cache_pool
5+
config:
6+
respect_cache_headers: true

Tests/Resources/Fixtures/config/full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
'stream_factory' => 'my_other_stream_factory',
8282
'config' => [
8383
'default_ttl' => 42,
84-
'respect_cache_headers' => false,
84+
'respect_response_cache_directives' => ['X-Foo', 'X-Bar'],
8585
],
8686
],
8787
'cookie' => [

Tests/Resources/Fixtures/config/full.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
<my_service type="service" service="my_auth_service"/>
4545
</authentication>
4646
<cache cache-pool="my_cache_pool" stream-factory="my_other_stream_factory">
47-
<config default-ttl="42" respect-cache-headers="false"/>
47+
<config default-ttl="42">
48+
<respect-response-cache-directives>X-Foo</respect-response-cache-directives>
49+
<respect-response-cache-directives>X-Bar</respect-response-cache-directives>
50+
</config>
4851
</cache>
4952
<cookie cookie-jar="my_cookie_jar"/>
5053
<decoder enabled="false"/>

Tests/Resources/Fixtures/config/full.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ httplug:
5656
stream_factory: my_other_stream_factory
5757
config:
5858
default_ttl: 42
59-
respect_cache_headers: false
59+
respect_response_cache_directives:
60+
- X-Foo
61+
- X-Bar
6062
cookie:
6163
cookie_jar: my_cookie_jar
6264
decoder:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
httplug:
2+
plugins:
3+
cache:
4+
cache_pool: my_cache_pool
5+
config:
6+
respect_cache_headers: true
7+
respect_response_cache_directives:
8+
- X-Foo
9+
- X-Bar

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase
3636
'enabled' => false,
3737
'stream_factory' => 'httplug.stream_factory',
3838
'config' => [
39-
'default_ttl' => null,
40-
'respect_cache_headers' => null,
39+
'default_ttl' => 0,
4140
],
4241
],
4342
'cookie' => [
@@ -196,7 +195,7 @@ public function testSupportsAllConfigFormats()
196195
'stream_factory' => 'my_other_stream_factory',
197196
'config' => [
198197
'default_ttl' => 42,
199-
'respect_cache_headers' => false,
198+
'respect_response_cache_directives' => ['X-Foo', 'X-Bar'],
200199
],
201200
],
202201
'cookie' => [
@@ -279,13 +278,24 @@ public function testInvalidAuthentication()
279278
$this->assertProcessedConfigurationEquals([], [$file]);
280279
}
281280

281+
/**
282+
* @group legacy
283+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
284+
* @expectedExceptionMessage Invalid configuration for path "httplug.plugins.cache.config": You can't provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaniously. Use "respect_response_cache_directives" instead.
285+
*/
286+
public function testInvalidCacheConfig()
287+
{
288+
$file = __DIR__.'/../../Resources/Fixtures/config/invalid_cache_config.yml';
289+
$this->assertProcessedConfigurationEquals([], [$file]);
290+
}
291+
282292
/**
283293
* @group legacy
284294
*/
285295
public function testBackwardCompatibility()
286296
{
287297
$formats = array_map(function ($path) {
288-
return __DIR__.'/../../Resources/Fixtures//'.$path;
298+
return __DIR__.'/../../Resources/Fixtures/'.$path;
289299
}, [
290300
'config/bc/toolbar.yml',
291301
'config/bc/toolbar_auto.yml',
@@ -296,6 +306,24 @@ public function testBackwardCompatibility()
296306
}
297307
}
298308

309+
/**
310+
* @group legacy
311+
*/
312+
public function testCacheConfigDeprecationCompatibility()
313+
{
314+
$file = __DIR__.'/../../Resources/Fixtures/config/bc/cache_config.yml';
315+
$config = $this->emptyConfig;
316+
$config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
317+
'enabled' => true,
318+
'cache_pool' => 'my_cache_pool',
319+
'config' => [
320+
'default_ttl' => 0,
321+
'respect_cache_headers' => true,
322+
],
323+
]);
324+
$this->assertProcessedConfigurationEquals($config, [$file]);
325+
}
326+
299327
/**
300328
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
301329
* @expectedExceptionMessage Can't configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"php-http/client-implementation": "^1.0",
2121
"php-http/message-factory": "^1.0.2",
2222
"php-http/client-common": "^1.2",
23-
"php-http/cache-plugin": "^1.3",
23+
"php-http/cache-plugin": "^1.4",
2424
"php-http/logger-plugin": "^1.0",
2525
"php-http/stopwatch-plugin": "^1.0",
2626
"symfony/options-resolver": "^2.8 || ^3.0",

0 commit comments

Comments
 (0)