Skip to content

Commit 0e5533d

Browse files
authored
Merge pull request #414 from php-http/allow-null-ttl
allow to configure default_ttl to null
2 parents b924cf6 + 8529a02 commit 0e5533d

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
# 1.26.0 - 2022-03-17
6+
7+
- Fixed you can now configure the cache plugin default_ttl with `null`.
8+
59
# 1.25.0 - 2021-11-26
610
- Added PHP 8.1 support
711
- Added Symfony 6 support

Diff for: src/DependencyInjection/Configuration.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,14 @@ private function createCachePluginNode()
713713
->integerNode('cache_lifetime')
714714
->info('The minimum time we should store a cache item')
715715
->end()
716-
->integerNode('default_ttl')
716+
->scalarNode('default_ttl')
717717
->info('The default max age of a Response')
718+
->validate()
719+
->ifTrue(function ($v) {
720+
return null !== $v && !is_int($v);
721+
})
722+
->thenInvalid('default_ttl must be an integer or null, got %s')
723+
->end()
718724
->end()
719725
->arrayNode('blacklisted_paths')
720726
->info('An array of regular expression patterns for paths not to be cached. Defaults to an empty array.')

Diff for: tests/Resources/Fixtures/config/ttl_null.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
httplug:
2+
clients:
3+
test:
4+
plugins:
5+
-
6+
cache:
7+
cache_pool: my_custom_cache_pull
8+
config:
9+
default_ttl: null

Diff for: tests/Unit/DependencyInjection/ConfigurationTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,37 @@ public function testInvalidCapturedBodyLengthString(): void
453453
$this->expectExceptionMessage('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null');
454454
$this->assertProcessedConfigurationEquals([], [$file]);
455455
}
456+
457+
public function testNullDefaultTtl(): void
458+
{
459+
$file = __DIR__.'/../../Resources/Fixtures/config/ttl_null.yml';
460+
$config = $this->emptyConfig;
461+
$config['clients'] = [
462+
'test' => [
463+
'factory' => 'httplug.factory.auto',
464+
'service' => null,
465+
'public' => null,
466+
'flexible_client' => false,
467+
'http_methods_client' => false,
468+
'batch_client' => false,
469+
'config' => [],
470+
'plugins' => [
471+
[
472+
'cache' => [
473+
'config' => [
474+
'default_ttl' => null,
475+
'blacklisted_paths' => [],
476+
'methods' => ['GET', 'HEAD'],
477+
'cache_listeners' => [],
478+
],
479+
'cache_pool' => 'my_custom_cache_pull',
480+
'enabled' => true,
481+
'stream_factory' => 'httplug.stream_factory',
482+
],
483+
],
484+
],
485+
],
486+
];
487+
$this->assertProcessedConfigurationEquals($config, [$file]);
488+
}
456489
}

0 commit comments

Comments
 (0)