Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,13 @@ private function registerHttpCacheConfiguration(ContainerBuilder $container, arr
{
$loader->load('http_cache.php');

// Concrete purger services are always registered when the http-cache package is present,
// so userland can decorate or inject them even when invalidation is disabled (#8095).
// The invalidation listener, the AddTagsProcessor and the HTTP-client wiring stay gated below.
if (interface_exists(\ApiPlatform\HttpCache\PurgerInterface::class)) {
$loader->load('http_cache_purger.php');
}

if (!$this->isConfigEnabled($container, $config['http_cache']['invalidation'])) {
return;
}
Expand All @@ -879,7 +886,6 @@ private function registerHttpCacheConfiguration(ContainerBuilder $container, arr
}

$loader->load('state/http_cache_purger.php');
$loader->load('http_cache_purger.php');

foreach ($config['http_cache']['invalidation']['scoped_clients'] as $client) {
$definition = $container->getDefinition($client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,42 @@ public function testPropertyInfoExtractorsDoNotLeakIntoFrameworkPropertyInfo():
}
}
}

/**
* @see https://github.com/api-platform/core/issues/8095
*/
public function testHttpCachePurgersRegisteredWhenInvalidationDisabled(): void
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['http_cache']['invalidation']['enabled'] = false;
(new ApiPlatformExtension())->load($config, $this->container);

$this->assertContainerHasService('api_platform.http_cache.purger.varnish.ban');
$this->assertContainerHasService('api_platform.http_cache.purger.varnish.xkey');
$this->assertContainerHasService('api_platform.http_cache.purger.souin');
$this->assertContainerHasAlias('api_platform.http_cache.purger.varnish');

$this->assertNotContainerHasService('api_platform.doctrine.listener.http_cache.purge');
$this->assertNotContainerHasService('api_platform.http_cache_purger.processor.add_tags');
$this->assertFalse($this->container->hasAlias('api_platform.http_cache.purger'));
}

/**
* @see https://github.com/api-platform/core/issues/8095
*/
public function testHttpCachePurgersAndListenerRegisteredWhenInvalidationEnabled(): void
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['http_cache']['invalidation']['enabled'] = true;
(new ApiPlatformExtension())->load($config, $this->container);

$this->assertContainerHasService('api_platform.http_cache.purger.varnish.ban');
$this->assertContainerHasService('api_platform.http_cache.purger.varnish.xkey');
$this->assertContainerHasService('api_platform.http_cache.purger.souin');
$this->assertContainerHasAlias('api_platform.http_cache.purger.varnish');

$this->assertContainerHasService('api_platform.doctrine.listener.http_cache.purge');
$this->assertContainerHasService('api_platform.http_cache_purger.processor.add_tags');
$this->assertContainerHasAlias('api_platform.http_cache.purger');
}
}
Loading