Skip to content

fix(symfony): register http cache purgers independently of invalidation flag#8260

Open
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/symfony-http-cache-purgers-always-register-8095
Open

fix(symfony): register http cache purgers independently of invalidation flag#8260
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/symfony-http-cache-purgers-always-register-8095

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 8, 2026

Summary

When http_cache.invalidation.enabled is false, the bundle previously skipped loading the concrete purger services (api_platform.http_cache.purger.varnish.ban, .varnish.xkey, .souin, plus the api_platform.http_cache.purger.varnish alias). Userland decorating or injecting those purgers then booted with a ServiceNotFoundException. This PR moves the purger services load outside the invalidation early-return — gated only on interface_exists(PurgerInterface::class) — while keeping the listener, AddTagsProcessor, scoped HTTP-clients and the api_platform.http_cache.purger alias behind the invalidation flag.

Reproduction

App\HttpCache\PurgeHttpCacheListener:
    decorates: 'api_platform.doctrine.listener.http_cache.purge'
    bind:
        $purger: '@api_platform.http_cache.purger'

Boot a kernel with api_platform.http_cache.invalidation.enabled: false: container compilation failed because api_platform.http_cache.purger.varnish.ban (the decorated alias target) was missing.

Test plan

  • Added failing test (testHttpCachePurgersRegisteredWhenInvalidationDisabled) covering the bug.
  • Added symmetric test (testHttpCachePurgersAndListenerRegisteredWhenInvalidationEnabled) covering the unchanged path.
  • Both tests pass after the fix.
  • Surrounding ApiPlatformExtensionTest and tests/Symfony/Bundle/DependencyInjection/ConfigurationTest still pass locally (the pre-existing testSwaggerUiDisabledConfiguration failure is unrelated and reproduces on upstream/4.3 HEAD).
  • vendor/bin/php-cs-fixer fix --dry-run and vendor/bin/phpstan analyse clean on touched files.

Fixes #8095

…on flag

When `http_cache.invalidation.enabled` is false, the bundle previously skipped
loading `http_cache_purger.php`, which left the concrete purger services
(`api_platform.http_cache.purger.varnish.ban`, `.varnish.xkey`, `.souin` plus
the `api_platform.http_cache.purger.varnish` alias) undefined. Userland that
decorates or injects those purgers — common when running multiple environments
where invalidation is off in dev/test — then booted with a
`ServiceNotFoundException`.

Move the purger services load outside the invalidation early return, gated only
on `interface_exists(PurgerInterface::class)` so missing
`api-platform/http-cache` still skips cleanly. The invalidation listener
(`api_platform.doctrine.listener.http_cache.purge`), the `AddTagsProcessor`
state processor, the `scoped_clients` tagging, the `urls`/`varnish_urls`
ScopingHttpClient wiring and the `api_platform.http_cache.purger` alias remain
behind the invalidation flag — only the concrete purger classes are exposed
unconditionally.

Fixes api-platform#8095
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant