Skip to content

#67 - Tag a Symfony cache pool directly as a cache adapter, without an adapter class - #68

Merged
njoubert-cleverage merged 1 commit into
mainfrom
67
Oct 21, 2026
Merged

njoubert-cleverage merged 1 commit into
mainfrom
67

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #67.

  • RegisterAdaptersPass: a service tagged cleverage.cache.adapter with a code whose class implements Symfony\Component\Cache\Adapter\AdapterInterface but not the AdapterInterface of the bundle is wrapped in an Adapter with this code (private .cleverage_cache_process.adapter.<code> service), still loaded lazily from the locator. The class is read from the definition, or from its parent (pools defined as services, as the FrameworkBundle ones), parameters resolved.
  • The adapters implementing the AdapterInterface of the bundle are registered unchanged; a service whose class cannot be loaded is registered as is (checked when fetched, as before).
  • A tagged service implementing neither interface fails the container compilation with an explicit message.
  • A pool must be tagged with a code (the deprecated registration without code is unchanged).
  • The pools of framework.cache.pools cannot be tagged by the application (their definitions are created by the FrameworkBundle): the documented Adapter service wrapping them stays the way to use them.
  • Documentation: reference (tag on a pool, examples with an ArrayAdapter and a pool parent: cache.adapter.filesystem, notes), the "share data between branches" cookbook no longer needs a PHP class. CHANGELOG.
services:
    app.cache.memory:
        class: Symfony\Component\Cache\Adapter\ArrayAdapter
        tags:
            - { name: cleverage.cache.adapter, code: memory }

Tests: RegisterAdaptersPassTest (pool and pool with a parent wrapped, lazily, one pool for two codes, unknown class or no class registered as is, neither interface → compilation error); KernelTest (an ArrayAdapter and a parent: cache.adapter.array + cache.pool service in a real application).

Checked in the container (PHP 8.5): 82 tests, 100 % of the lines, no risky test (pcov coverage), also with --prefer-lowest. PHPStan, PHP-CS-Fixer and Rector OK. In the demo (vendor patched temporarily), the MemoryAdapter class replaced by a parent: cache.adapter.array pool tagged directly: lint:container OK and the demo.cache.* processes give the same results.

Requirements

  • Documentation updates
    • Reference
    • Changelog
  • Unit tests

Breaking changes

None: the services already tagged keep working; a tagged service implementing neither interface failed when used (addAdapter() typed in the released versions, check of the registry since #53).

🤖 Generated with Claude Code

…n adapter class

A service implementing the AdapterInterface of the Cache component (a Symfony
adapter or a pool defined with "parent") can be tagged cleverage.cache.adapter
with a code: RegisterAdaptersPass wraps it in an Adapter with this code, loaded
lazily. A tagged service implementing neither interface fails the compilation.
Tests, documentation and CHANGELOG updated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

Tag a Symfony cache pool directly as a cache adapter, without an adapter class

1 participant