Skip to content

Commit 24d8740

Browse files
author
Till Hildebrandt
committed
Added cache_listeners to Configuration and Extension
1 parent 3bd469e commit 24d8740

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\HttplugBundle\DependencyInjection;
44

55
use Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator;
6+
use Http\Client\Common\Plugin\Cache\Listener\CacheListener;
67
use Http\Client\Common\Plugin\CachePlugin;
78
use Http\Client\Common\Plugin\Journal;
89
use Http\Client\Plugin\Vcr\NamingStrategy\NamingStrategyInterface;
@@ -739,6 +740,12 @@ private function createCachePluginNode()
739740
->end()
740741
->end()
741742
->end()
743+
->arrayNode('cache_listeners')
744+
->info('An array of services to act on the response based on the results of the cache check. Must implement ' . CacheListener::class . ' Defaults to an empty array.')
745+
->defaultValue([])
746+
->prototype('scalar')
747+
->end()
748+
->end()
742749
->scalarNode('respect_cache_headers')
743750
->info('Whether we should care about cache headers or not [DEPRECATED]')
744751
->beforeNormalization()

src/DependencyInjection/HttplugExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,17 @@ private function configurePluginByName($name, Definition $definition, array $con
203203
switch ($name) {
204204
case 'cache':
205205
$options = $config['config'];
206+
206207
if (!empty($options['cache_key_generator'])) {
207208
$options['cache_key_generator'] = new Reference($options['cache_key_generator']);
208209
}
209210

211+
if (!empty($options['cache_listeners'])) {
212+
foreach ($options['cache_listeners'] as $i => $listener) {
213+
$options['cache_listeners'][$i] = new Reference($listener);
214+
}
215+
}
216+
210217
$definition
211218
->replaceArgument(0, new Reference($config['cache_pool']))
212219
->replaceArgument(1, new Reference($config['stream_factory']))

0 commit comments

Comments
 (0)