Skip to content

Commit 72db381

Browse files
committed
Added plugin support for purge clients
1 parent f53a80b commit 72db381

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace EzSystems\PlatformHttpCacheBundle\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
class PurgeTypeSettingsPass implements CompilerPassInterface
9+
{
10+
public function process(ContainerBuilder $container)
11+
{
12+
$purgeType = $container->getParameter('ezpublish.http_cache.purge_type');
13+
$purgeService = null;
14+
15+
$purgeClientServiceIds = $container->findTaggedServiceIds('ezplatform.http_cache.purge_client');
16+
foreach ($purgeClientServiceIds as $purgeClientServiceId => $attributes) {
17+
$hasPurgeTypeAttribute = false;
18+
foreach ($attributes as $attribute) {
19+
if (array_key_exists('purge_type', $attribute)) {
20+
$hasPurgeTypeAttribute = true;
21+
if ($purgeType === $attribute['purge_type']) {
22+
$purgeService = $purgeClientServiceId;
23+
break;
24+
}
25+
}
26+
}
27+
if (!$hasPurgeTypeAttribute) {
28+
throw new \InvalidArgumentException("Missing attribute 'purge_type' in tagged service '$purgeClientServiceId'.");
29+
}
30+
}
31+
32+
if ($purgeService === null) {
33+
throw new \InvalidArgumentException("No driver found being able to handle purge_type '$purgeType'.");
34+
}
35+
36+
$container->setAlias('ezplatform.http_cache.purge_client', $purgeService);
37+
}
38+
}

src/EzSystemsPlatformHttpCacheBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use EzSystems\PlatformHttpCacheBundle\DependencyInjection\Compiler\ResponseTaggersPass;
66
use EzSystems\PlatformHttpCacheBundle\DependencyInjection\Compiler\KernelPass;
7+
use EzSystems\PlatformHttpCacheBundle\DependencyInjection\Compiler\PurgeTypeSettingsPass;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89
use Symfony\Component\HttpKernel\Bundle\Bundle;
910

@@ -15,5 +16,6 @@ public function build(ContainerBuilder $container)
1516

1617
$container->addCompilerPass(new ResponseTaggersPass());
1718
$container->addCompilerPass(new KernelPass());
19+
$container->addCompilerPass(new PurgeTypeSettingsPass());
1820
}
1921
}

src/Resources/config/services.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ services:
1313
ezplatform.http_cache.purge_client.fos:
1414
class: EzSystems\PlatformHttpCacheBundle\PurgeClient\FOSPurgeClient
1515
arguments: ["@ezplatform.http_cache.cache_manager"]
16+
tags:
17+
- {name: ezplatform.http_cache.purge_client, purge_type: http}
1618

1719
ezplatform.http_cache.purge_client.local:
1820
class: EzSystems\PlatformHttpCacheBundle\PurgeClient\LocalPurgeClient
1921
arguments: ["@ezplatform.http_cache.store"]
22+
tags:
23+
- {name: ezplatform.http_cache.purge_client, purge_type: local}
2024

2125
ezplatform.http_cache.store:
2226
alias: ezplatform.http_cache.tag_aware_store

0 commit comments

Comments
 (0)